0

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

xchan
  • 37
  • 5
  • Have you tried going through it with a profiler? That will easily tell you what is wrong. – Anubian Noob May 06 '14 at 01:04
  • @AnubianNoob I do not know about that profiler thing, can you briefly explain where and how can I access that? Or what it does? – xchan May 06 '14 at 01:06
  • What IDE are you using? – Anubian Noob May 06 '14 at 01:07
  • Netbeans 8.0 Beta I found the profiler, the most percentage has is int[]. What does this mean? – xchan May 06 '14 at 01:09
  • Netbeans 8.0 Beta I found the profiler, the most percentage has is int[] with about 8,991,824 B Live Bytes and 608 Live Objects. What does this mean? – xchan May 06 '14 at 01:15
  • That's probably your memory leak. You have 608 int arrays taking up 9 million bytes of memory. You can play around with the options to figure out where that int array is. – Anubian Noob May 06 '14 at 01:18
  • I have scanned through all my codes and confirmed that I never used int arrays. – xchan May 06 '14 at 01:28
  • It can also be in a library or system class you use. There are options to see what class has the object. – Anubian Noob May 06 '14 at 01:29

2 Answers2

1

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

Community
  • 1
  • 1
vkg
  • 1,839
  • 14
  • 15
1

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.

Anubian Noob
  • 13,426
  • 6
  • 53
  • 75
  • 1
    I was able to reduce up to 5 million bytes of Int[] by tracking it with profiler. For those who has the same problem, Scaling an image using getScaledInstance takes alot of memory, istead draw the image using bufferedImage and Graphics2D :) thanks! – xchan May 06 '14 at 02:10
  • Awesome, glad I could help :). Profiling/Debugging is a good skill to have. – Anubian Noob May 06 '14 at 02:15