Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent memory leak of Client by unregistering parent dispose method #3088

Merged
merged 2 commits into from Apr 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions java/libraries/net/src/processing/net/Client.java
Expand Up @@ -61,6 +61,7 @@ public class Client implements Runnable {
int bufferIndex;
int bufferLast;

boolean isDisposeRegistered = false;

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

parent.registerMethod("dispose", this);
isDisposeRegistered = true;

// reflection to check whether host sketch has a call for
// public void clientEvent(processing.net.Client)
Expand Down Expand Up @@ -158,6 +160,10 @@ public void stop() {
disconnectEventMethod = null;
}
}
if(isDisposeRegistered){
parent.unregisterMethod("dispose", this);
isDisposeRegistered = false;
}
dispose();
}

Expand Down