Fixed memory leak while starting up/closing plugin multiple times
This commit is contained in:
parent
82af836113
commit
6779bacf38
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ch.psi.zmq</groupId>
|
||||
<artifactId>ch.psi.zmq.imagej</artifactId>
|
||||
<version>0.1.0</version>
|
||||
<version>0.1.1</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -35,6 +35,8 @@ public class ZeroMQViewer implements PlugIn {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ZeroMQViewer.class.getName());
|
||||
|
||||
private static final int HIGH_WATER_MARK = 10;
|
||||
|
||||
private ImagePlus img;
|
||||
|
||||
private boolean flipX = false;
|
||||
@ -96,6 +98,9 @@ public class ZeroMQViewer implements PlugIn {
|
||||
|
||||
while (isPluginRunning) {
|
||||
semaphore.acquire();
|
||||
if(!isPluginRunning){ // if plugin was terminated while waiting for the semaphore exit loop
|
||||
break;
|
||||
}
|
||||
collect=true;
|
||||
hinfo.setVisible(true);
|
||||
try{
|
||||
@ -107,8 +112,7 @@ public class ZeroMQViewer implements PlugIn {
|
||||
int port = Integer.parseInt(textPort.getText());
|
||||
String method = (String) comboBoxMethod.getSelectedItem();
|
||||
|
||||
|
||||
context = ZMQ.context(1);
|
||||
context = ZMQ.context();
|
||||
if(method.equals("PULL")){
|
||||
socket = context.socket(ZMQ.PULL);
|
||||
}
|
||||
@ -120,6 +124,7 @@ public class ZeroMQViewer implements PlugIn {
|
||||
logger.severe("Method not supported");
|
||||
collect=false;
|
||||
}
|
||||
socket.setHWM(HIGH_WATER_MARK);
|
||||
socket.connect("tcp://"+hostname+":"+port);
|
||||
|
||||
logger.info("Connected to: tcp://"+hostname+":"+port);
|
||||
@ -152,7 +157,9 @@ public class ZeroMQViewer implements PlugIn {
|
||||
|
||||
timer.stop();
|
||||
|
||||
img.close();
|
||||
if(img!=null){
|
||||
img.close();
|
||||
}
|
||||
frame.setVisible(false);
|
||||
|
||||
IJ.showStatus("Exiting ZeroMQ Viewer");
|
||||
@ -403,6 +410,7 @@ public class ZeroMQViewer implements PlugIn {
|
||||
public class FrameExitListener extends WindowAdapter {
|
||||
public void windowClosing(WindowEvent event) {
|
||||
isPluginRunning = false;
|
||||
semaphore.release(); // release the wait semaphore in case the plugin is stucked in there.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user