Skip to content

Commit 4716319

Browse files
committed
Prevent memory leak by unregistering parent dispose method
1 parent 10727da commit 4716319

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

java/libraries/net/src/processing/net/Client.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class Client implements Runnable {
6161
int bufferIndex;
6262
int bufferLast;
6363

64+
boolean isDisposeRegistered = false;
6465

6566
/**
6667
* @param parent typically use "this"
@@ -81,6 +82,7 @@ public Client(PApplet parent, String host, int port) {
8182
thread.start();
8283

8384
parent.registerMethod("dispose", this);
85+
isDisposeRegistered = true;
8486

8587
// reflection to check whether host sketch has a call for
8688
// public void clientEvent(processing.net.Client)
@@ -158,6 +160,9 @@ public void stop() {
158160
disconnectEventMethod = null;
159161
}
160162
}
163+
if(isDisposeRegistered){
164+
parent.unregisterMethod("dispose", this);
165+
}
161166
dispose();
162167
}
163168

0 commit comments

Comments
 (0)