Prevent memory leak by unregistering parent dispose method

This commit is contained in:
kfeuz
2015-02-05 00:24:08 -07:00
parent 10727da7f1
commit 4716319471
@@ -61,6 +61,7 @@ public class Client implements Runnable {
int bufferIndex;
int bufferLast;
boolean isDisposeRegistered = false;
/**
* @param parent typically use "this"
@@ -81,6 +82,7 @@ public class Client implements Runnable {
thread.start();
parent.registerMethod("dispose", this);
isDisposeRegistered = true;
// reflection to check whether host sketch has a call for
// public void clientEvent(processing.net.Client)
@@ -158,6 +160,9 @@ public class Client implements Runnable {
disconnectEventMethod = null;
}
}
if(isDisposeRegistered){
parent.unregisterMethod("dispose", this);
}
dispose();
}