JDK-6470522 : memory leak when running applet with 5u8
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0u8
  • Priority: P1
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows,windows_xp
  • CPU: x86
  • Submitted: 2006-09-14
  • Updated: 2014-02-27
  • Resolved: 2006-09-28
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
POGO.com report a memory regression in 5u8.   Run a few simple applets (or the applet supplied from pogo) in the same browser, and then navigate the browser to a page without any applet.  Perform GC.

If you hook up JProfiler, you will still see instances of AppletViewer and IExplorerEmbedded frame there, with a JNI Gloal Ref referenceing it, preventing it from GC.

JProfiler screenshot:
http://javaweb.sfbay.sun.com/~ngthomas/pogo/applet-jni-ref.PNG

Pogo.com simple applet source:
import java.applet.Applet;

public class JNIGlobalReferenceLeakDemoApplet extends Applet {
    private int[] mBigLeak;

    public void init() {
        mBigLeak = new int[1000000];
        for (int i = 0; i < mBigLeak.length; i++) {
            mBigLeak[i] = i;
        }
    }
}

With 5u7, the problem cannot be reproduced.

Also, if I replace awt.dll and rt.jar from 5u7 to 5u8, I cannot reproduce the problem too.  So I am assigning the bug to awt so they can take a look.

Comments
SUGGESTED FIX *** /net/karanar/export/os154571/Mustang.RC/webrev/src/windows/native/sun/windows/awt_Cursor.cpp- --- /net/karanar/export/os154571/Mustang.RC/webrev/src/windows/native/sun/windows/awt_Cursor.cpp *** 487,497 **** --- 487,499 ---- if(jobject jpeer = AwtObject::GetPeerForTarget(env, jcomp)) { if(AwtComponent *awtComponent = (AwtComponent*)JNI_GET_PDATA(jpeer)) { awtComponent->setCursorCache(hCursor); } + env->DeleteLocalRef(jpeer); } + env->DeleteGlobalRef(jcomp); } if( TRUE == awtCursor->IsCustomCursor() ) { AwtToolkit::GetInstance().NotifyCustomCursor(); }
15-09-2006

EVALUATION The source of the problem is the same as for 6351698.
15-09-2006

EVALUATION Running the test with 1.5.0_08 (b01 and b03) and hprof doesn't show any global refs, but I noticed that sometimes applet instances aren't GCed even if there are no refs to them. A bug in hprof or jhat? I don't know... Using JProfiler I can see a global ref to the applet, but I can't say when it was allocated.
15-09-2006

EVALUATION The submitter has confirmed that the bug is not reproducible with 6.0-rc.
14-09-2006

EVALUATION I have looked through all the AWT fixes into 5.0u8 and all of them handle JNI global refs correctly. Another possible candidate is 6334864, but I don't have a webrev for it, will try to get it as soon as possible. I have also tried to run the applet with 6.0 and hprof, and haven't noticed any global refs. It seems that the problem is 5.0u8-specific.
14-09-2006