Question

i've been making an application and i've been tracking its memory usage. The app's memory is about 58,676 K as seen below. enter image description here

This is my GUI.

enter image description here

That close button there has a function that makes that panel not Visible.

private final ActionListener closeButtonAL = new ActionListener(){

    @Override
    public void actionPerformed(ActionEvent e) {
        timeUtilities.getPanel().setVisible(false);
    }

};

I also have a button that makes the panel visible again.

private final ActionListener showPanelAL = new ActionListener(){

    @Override
    public void actionPerformed(ActionEvent e) {
        timeUtilities.getPanel().setVisible(true);
    }

};

The panel has been initialized already before the app starts showing.

My problem is that, by just making the GUI appear and closes it again and again increases the memory usage of the application.

Isn't this some sort of memory leak? Regardless of the answer, how do I prevent this matter?

enter image description here

Was it helpful?

Solution

You should use a profiler to locate your memory leak.

In NetBeans, at the top next to "Run Project" and "Debug Project" buttons is a "Profile Project" button (Alt-F2).

First run, it will may ask you to calibrate or something.

Afterwars, you can choose to analyse CPU or Memory. If you click on Memory, check "Simple," and click Run, you can run your project and see what's using memory.

OTHER TIPS

No that may not be a sign of memory leak. Because when you close and open the gui multiple times your app may be creating and discarding some objects. But JVM may not have garbage collected them yet. If you want the real picture use a profiling tool. Take heap dumps over time after the GC runs. This will tell you what is still remaining in the memory.

This can help you narrow down your hunt for a possible memory leak.

Simplest tools to profile.

  1. Netbeans comes with a built in profiler.
  2. Jconsole can also help a bit
  3. VisualVm can also aid a bit.

Also see this link how to analyze heapdumps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top