How to Discover the Source of Memory Leak with NetBeans Profiler
If you discover a memory leak using the Surviving Generations metrics during monitoring, the NetBeans Profiler enables you to easily find the code in your application where the leaking objects are created and fix the problem.
To find the suspect code, perform the following steps.Follow these steps to locate all the methods of your code where instances of the class are being created. The method(s) with the highest Surviving Generations value is most likely the cause of the leak.
- Switch the profiling mode to Memory mode and select Record stack trace for allocations.
- Open the live results and click the Generations column heading to sort the results by Surviving Generations value.The Live Profiling Results tab shows that the Object
entries are continuously being created and not released. This is a potential memory leak even though they don't consume much memory.
- Right-click the class with the continuously growing Surviving Generations value and choose Take Snapshot and Show Allocations Stack Traces in the popup menu.The IDE displays opens the stack trace that enables you to locate code that is the possible source of the leak. You can right-click the class name and choose Go to Source in the popup menu to open the class in the editor.