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.
  1. Switch the profiling mode to Memory mode and select Record stack trace for allocations.
  2. Open the live results and click the Generations column heading to sort the results by Surviving Generations value.Surviving Generations of NetBeans Profiler
    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.
  3. 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.
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.


Popular posts from this blog

How to get Active Transactions and Locks from MySQL

Example of a PAC file