2

I seems to have memory leak problems in my javaFX application, i have been using the net beans profiler tool to help me locate the source of the leaks but i have hit a wall as I'm not sure exactly what I'm doing.

now i have looked at tutorials,and they say to monitor the surviving generations of a object but I'm still unsure what to with this information. I have taken a screenshot of the highest surviving generation objects while i was monitoring my application.

Can someone explain to me what exactly i should be doing with these objects or are they actually causing a memory leak?

enter image description here

noobCoder
  • 370
  • 1
  • 8
  • 18
  • 1
    Have a look at this: http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java It's not an answer to your question but there are some good examples on how to create memory leaks in Java. This might help you locating your problem (if there exists one at all. Hard to say without knowing what your program is supposed to do ;) ) – whatTheFox Mar 22 '16 at 14:58
  • @noobCoder Were you able to find the problem using Eclipse MAT? – Paul MacGuiheen Mar 26 '16 at 20:17
  • not yet no,but it has pointed me in the right direction. I have currently put it on the back burner for the time being, as i feel i could sink a lot hours into finding the problem, which i simply don't have at the moment as i have to present my tool in the coming days. so all my efforts are currently being put into making sure that the tool runs correctly. – noobCoder Mar 27 '16 at 15:37

1 Answers1

1

A common source of unexpected high memory usage is adding objects to a collection and then not removing them when you are done (I see the image you posted shows a HashMap that may be an issue). The typical solution is to use a collection which will not keep an object alive once all other references to it are gone, see WeakHashMap for more info.

To dig into these types of issues further capture a hrpof (you can use VisualVM, JConsole, etc.) and then analyze it in Eclipse MAT or a similar tool.

Paul MacGuiheen
  • 628
  • 5
  • 17
  • see the weird thing is, i have searched all my `FXML` controller files and i haven't used `HashMaps` at any point so i can't even change the type of collection I'm using to a `WeakHashMap`. – noobCoder Mar 22 '16 at 14:53
  • Eclipse MAT can tell you what objects are consuming the most memory, and Merge Shortest Path To GC Root will tell you what is keeping them alive. If the HashMap turns out to be an issue that will tell you who owns it – Paul MacGuiheen Mar 22 '16 at 14:59
  • If you are using a JDK the Java Mission Control can do that as well. Here is a great tutorial for it: https://www.javacodegeeks.com/2015/03/oracle-java-mission-control-the-ultimate-guide.html – whatTheFox Mar 22 '16 at 15:11