Skip to content

Commit

Permalink
Fix threading error when deleting global refs. (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmelchior authored Sep 14, 2016
1 parent f1e1695 commit 074fbd7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ JNIEXPORT void JNICALL Java_io_realm_objectserver_Session_nativeUnbind
{
TR_ENTER(env)
JniSession* session = SS(sessionPointer);
session->close(env);
delete session; // TODO Can we avoid killing the session here?
}

Expand Down
7 changes: 6 additions & 1 deletion realm/realm-library/src/main/cpp/objectserver_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ class JniSession {
return m_sync_session;
}

// Call this just before destroying the object to release JNI ressources.
inline void close(JNIEnv* env)
{
env->DeleteGlobalRef(m_global_obj_ref);
}

~JniSession()
{
sync_client_env->DeleteGlobalRef(m_global_obj_ref);
delete m_sync_session;
}

Expand Down

0 comments on commit 074fbd7

Please sign in to comment.