P
phsamuel
Hi,
I have memory leakage problem using ImagePlus.show() when I use ij
library outside ImageJ. Even after I close the imageplus window, the
memory is not free. I tested the similar situation inside ImageJ and I
don't encounter any memory problem. My test code is attached at the
end. Press the "Show Image" button to show a big image stack. Press the
"show memory usage" to check memory usage. Apparently, no memory is
free after the big image stack is closed...
I am not a very experience Java/ImageJ programmer. Any advice will be
helpful.
samuel
//--------------------------------------------------
package bugReveal;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.process.ByteProcessor;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
public class ImagePlusShow extends JFrame {
private JPanel jContentPane = null; // @jve:decl-index=0:
private JButton jButton = null; // @jve:decl-index=0:
private JButton jButton1 = null;
ImagePlus createBigStackImagePlus()
{
ImageStack ims=new ImageStack(640,480);
ByteProcessor bp;
for (int i=0;i<50;i++)
{
bp = new ByteProcessor(640,480);
ims.addSlice("",bp);
}
ImagePlus imp=new ImagePlus("",ims);
return imp;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("Show Image");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
createBigStackImagePlus().show();
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("show memory usage");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println(IJ.currentMemory());
}
});
}
return jButton1;
}
/**
* @param args
*/
public static void main(String[] args) {
new ImagePlusShow();
}
/**
* This is the default constructor
*/
public ImagePlusShow() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
this.pack();
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJButton(), java.awt.BorderLayout.CENTER);
jContentPane.add(getJButton1(), java.awt.BorderLayout.SOUTH);
}
return jContentPane;
}
}
I have memory leakage problem using ImagePlus.show() when I use ij
library outside ImageJ. Even after I close the imageplus window, the
memory is not free. I tested the similar situation inside ImageJ and I
don't encounter any memory problem. My test code is attached at the
end. Press the "Show Image" button to show a big image stack. Press the
"show memory usage" to check memory usage. Apparently, no memory is
free after the big image stack is closed...
I am not a very experience Java/ImageJ programmer. Any advice will be
helpful.
samuel
//--------------------------------------------------
package bugReveal;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.process.ByteProcessor;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
public class ImagePlusShow extends JFrame {
private JPanel jContentPane = null; // @jve:decl-index=0:
private JButton jButton = null; // @jve:decl-index=0:
private JButton jButton1 = null;
ImagePlus createBigStackImagePlus()
{
ImageStack ims=new ImageStack(640,480);
ByteProcessor bp;
for (int i=0;i<50;i++)
{
bp = new ByteProcessor(640,480);
ims.addSlice("",bp);
}
ImagePlus imp=new ImagePlus("",ims);
return imp;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("Show Image");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
createBigStackImagePlus().show();
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("show memory usage");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println(IJ.currentMemory());
}
});
}
return jButton1;
}
/**
* @param args
*/
public static void main(String[] args) {
new ImagePlusShow();
}
/**
* This is the default constructor
*/
public ImagePlusShow() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
this.pack();
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJButton(), java.awt.BorderLayout.CENTER);
jContentPane.add(getJButton1(), java.awt.BorderLayout.SOUTH);
}
return jContentPane;
}
}