Mercurial > hg > release > icedtea7-forest-2.2 > jdk
changeset 5310:aa4796865129
7174718: [macosx] Regression in 7u6 b12: PopupFactory leaks DefaultFrames.
Summary: Fix memory management
Reviewed-by: art, serb
author | andrew |
---|---|
date | Wed, 12 Jun 2013 10:56:11 +0100 |
parents | 4deffbfca5f2 |
children | 38d529f9f4ab |
files | src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java src/macosx/native/sun/awt/AWTWindow.m |
diffstat | 2 files changed, 26 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Fri Mar 15 17:59:10 2013 +0100 +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Wed Jun 12 10:56:11 2013 +0100 @@ -61,6 +61,7 @@ private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage); private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename); private static native void nativeSetNSWindowSecurityWarningPositioning(long nsWindowPtr, double x, double y, float biasX, float biasY); + private static native void nativeDispose(long nsWindowPtr); private static native int nativeGetScreenNSWindowIsOn_AppKitThread(long nsWindowPtr); @@ -417,6 +418,7 @@ EventQueue.invokeLater(new Runnable() { public void run() { contentView.dispose(); + nativeDispose(getNSWindowPtr()); CPlatformWindow.super.dispose(); } });
--- a/src/macosx/native/sun/awt/AWTWindow.m Fri Mar 15 17:59:10 2013 +0100 +++ b/src/macosx/native/sun/awt/AWTWindow.m Wed Jun 12 10:56:11 2013 +0100 @@ -193,6 +193,7 @@ defer:NO]; if (self == nil) return nil; // no hope + [self.nsWindow release]; // the property retains the object already self.javaPlatformWindow = platformWindow; self.styleBits = bits; @@ -604,9 +605,9 @@ styleBits:styleBits frameRect:frameRect contentView:contentView]; + // the window is released is CPlatformWindow.nativeDispose() - if (window) CFRetain(window); - [window release]; // GC + if (window) CFRetain(window.nsWindow); }]; JNF_COCOA_EXIT(env); @@ -1029,6 +1030,27 @@ JNF_COCOA_EXIT(env); } +JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeDispose +(JNIEnv *env, jclass clazz, jlong windowPtr) +{ +JNF_COCOA_ENTER(env); + + NSWindow *nsWindow = OBJC(windowPtr); + [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ + AWTWindow *window = (AWTWindow*)[nsWindow delegate]; + + // AWTWindow holds a reference to the NSWindow in its nsWindow + // property. Unsetting the delegate allows it to be deallocated + // which releases the reference. This, in turn, allows the window + // itself be deallocated. + [nsWindow setDelegate: nil]; + + [window release]; + }]; + +JNF_COCOA_EXIT(env); +} + JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CMouseInfoPeer_nativeIsWindowUnderMouse (JNIEnv *env, jclass clazz, jlong windowPtr) {