Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can't isolate JNI memory leak

843829Jul 13 2007 — edited Jul 19 2007
I've been beating my head against this for a week. We have a server that was developed in house written entirely in java. Recently, we added a JNI hook to use an in house driver written in C++. This driver is used in other places outside the server and works fine (no memory leaks). When used within the server however, we get a pretty massive amount of leaked memory, approximately 200MB over 16 hours.

The native code is loaded via the System.loadLibrary call. After this, no methods are called on the Java class with the native methods (other than the constructor) and memory is still leaked according to the windows task manager.

I've tried the following to debug this:
1) Ran a profiler to ensure that the leaked memory is not on the heap. (The heaps size stays fairly constant at 70MB even though windows task manager reports increasing memory usage.)
2) Isolated the Java class with the native methods using a test harness (the test harness simply loads the class that interfaces with the C++ driver and busy-loops every 2.5 seconds printing out status messages). Then this was run, no memory was leaked.
3) Instrumented the C++ code with a memory leak checker (visual leak detector) and ran the server. Memory was leaked according to the windows task manager but the leak detector found no leaks.
4) Removed all references and links to the C++ driver from generated JNI header file and .cpp file (we have a .cpp file that implements the JNI generated header file and simply makes calls to the C++ code). When run inside the server, no memory was leaked according to the windows task manager.
5) Replaced the Java class file with a test implementation that uses no native methods and does not load the C++ library. No memory was leaked.
6) Modified the Java class with the native methods to simply load the library with System.loadLibrary and make absolutely no native calls. Memory was leaked.
7) We run with JDK 1.5.0_08-b3. I tried using 1.5.0_12-b4. Memory was still leaked.

So the only way it leaks is if it's used inside our server even if we simply load the library with System.loadLibrary we get leaked memory. The thing that puzzles me most is why does it leak there and not when used by the test harness even when we only load the library but make no calls??

We are running in the following environment:
1) Windows Server 2003 Web Edition SP1
2) JDK 1.5.0_08-b3 (also 1.5.0_12-b4)
3) Intel Xeon 3GHz
4) C++ code compiled by Visual C++ 7.1.6030
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 16 2007
Added on Jul 13 2007
1 comment
439 views