Commit a19a556c authored by Ludovic Fauvet's avatar Ludovic Fauvet

Release the eventManager global reference on-demand

This fixes a memory leak in the JNI.
parent 2538b5cb
......@@ -248,8 +248,21 @@ int currentSdk( JNIEnv *p_env, jobject thiz )
return version;
}
void Java_org_videolan_vlc_android_LibVLC_detachEventManager(JNIEnv *env, jobject thiz)
{
if (eventManagerInstance != NULL) {
(*env)->DeleteGlobalRef(env, eventManagerInstance);
eventManagerInstance = NULL;
}
}
void Java_org_videolan_vlc_android_LibVLC_setEventManager(JNIEnv *env, jobject thiz, jobject eventManager)
{
if (eventManagerInstance != NULL) {
(*env)->DeleteGlobalRef(env, eventManagerInstance);
eventManagerInstance = NULL;
}
jclass cls = (*env)->GetObjectClass(env, eventManager);
if (!cls) {
LOGE("setEventManager: failed to get class reference");
......@@ -261,6 +274,7 @@ void Java_org_videolan_vlc_android_LibVLC_setEventManager(JNIEnv *env, jobject t
LOGE("setEventManager: failed to get the callback method");
return;
}
eventManagerInstance = (*env)->NewGlobalRef(env, eventManager);
}
......
......@@ -272,4 +272,6 @@ public class LibVLC {
private native byte[] getThumbnail(int instance, String filePath, int i_width, int i_height);
public native void setEventManager(EventManager eventManager);
public native void detachEventManager();
}
......@@ -105,9 +105,11 @@ public class PlayerActivity extends Activity {
} catch (LibVlcException e) {
e.printStackTrace();
}
EventManager em = new EventManager(eventHandler);
mLibVLC.setEventManager(em);
if (mLibVLC != null) {
EventManager em = new EventManager(eventHandler);
mLibVLC.setEventManager(em);
}
/* debug */
// lockScreen();
......@@ -129,7 +131,13 @@ public class PlayerActivity extends Activity {
super.onPause();
}
@Override
protected void onDestroy() {
if (mLibVLC != null)
mLibVLC.detachEventManager();
super.onDestroy();
}
@Override
public boolean onTrackballEvent(MotionEvent event) {
showOverlay();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment