DevPartner Java 3 Memory Leak Profiling Showing Active Thread Stack Leak

0 Likes

Problem:

When looking at the call graph of  Memory Leak profiling with DevPartner Java Edition, I see a node with the name Active Thread Stack.

Resolution:

Active Thread Stack means there is a reference to the object from a local variable in a currently running thread.

It should tell you which method holds the reference on the line between the objects.

It's generally a very easy memory leak to fix. Here's an example:

Person p = null;

while( true )

{

p = waitForConnection();

processConnectedPerson( p );

// fix here

}

In this case, even though we're done with Person p after the end of processConnectedPerson(), the person object is "leaked" until there is another connection because there's still a reference to it from the local variable until it's overwritten when the waitForConnection() returns.

In the above, it's fixed by adding the line "p = null;" in the "// fix here" part, above.

If you're allocating objects from a JNI native method, you might find that the JNI handle tracker holds onto the reference for you, until you return from that JNI method. If the JNI method never returned, you might see a leak like this.

If this is the case, when you're done with it, explicitly make a call to the JNI function DeleteLocalRef to wipe the reference manually.

Old KB# 11248
Comment List
Anonymous
Related Discussions
Recommended