Search code examples
javamysqlout-of-memoryheap-memoryvisualvm

Java Memory usage continuously growing till OutOfMemory Exception


I have a program which parses files and stores the data in a mysql-Database. My Problem is that the Heap space(I use VisualVM to follow them) is growing. And the Memory usage(ps aux --sort -rss) is also growing.

When the HeapSize reaches the MaxHeapsize of ~128 MB I get an OutOfMemory-Exception.

How can I determine which data this is? Or what is not dealocated?

heap size


Solution

  • You need to do a memory trace by using the memory profiler in VisualVM.

    A simple way to do a memory profile is to run

    jmap -histo:live {pid} | head
    

    If you are using SQL, the most likely cause of a memory leak is failing to clean up your JDBC resources. I suggest you make sure you close off your Statements and ResultSets.