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!

JNI and Out of Memory errors

843829Jan 21 2003 — edited Jan 23 2003
Hi,

At my job, we seem to have a memory leak related to JNI. We know we
have a memory leak because we keep getting Out of Memory errors even
after increasing the maximum heap size to more than 256 megs. And we
know that this is the application that is eating up all the system
memory.

We are running under Windows 2000, with both JDK 1.3.0 and JDK 1.4.1.

We tried looking at the problem under JProbe, but it shows a stable
Java heap (no problems, except that the Windows task manager shows it
growing and growing...)

I tried a strip down version, where I set the max heap size to 1 Meg,
and print out the total memory, memory used, and maximum memory used at
a 5 sec interval.

Memory used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory().

Well, I let that strip down version running for about a day. The
maximum memory used has stabilized to about 1.1 Meg, and has not
increased. The current memory used increases until it gets to some
threshold, then it decreases again. However, the Windows task manager
shows the memory increasing -- and currently it is at 245 Megs!

In the lab, the behavior we see with the Windows task manager is as
follows:

1. Total memory used in the system increases until some threshold.
2. Then it goes back down by about 100 Megs.
3. This cycle continues, but at each cycle the memory goes back down
less and less, until the app crashes.

Now, our theory is that JNI is consuming all this memory (maybe we are
using JNI wrong). That's the only explanation we can come up with to
explain what we have seen (Java showing an OK heap, but the task
manager showing it growing, until crashing).

Does that make sense? Can the new operator throw an Out of Memory
error if the system does not have enough memory to give it, even if
there is still free heap space as far as the Runtime object is
concerned? Does the Runtime object figures objects allocated through
JNI methods into the heap used space?

Note that I know the task manager is not a reliable indicator.
However, I don't think a Java app is supposed to runaway with system
memory -- the problem is not simply that the Java app is consuming too
much memory, but that it seems to always want more memory. Besides, we
do get the Out of Memory error.

Thanks for your help,

Nicolas Rivera
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 20 2003
Added on Jan 21 2003
3 comments
1,104 views