diff --git a/src/macosx/native/sun/awt/CFRetainedResource.m b/src/macosx/native/sun/awt/CFRetainedResource.m index 1371189b83f85f1510e92678a6b288ea3a4939f9..b5650cdd63cf57c6c780a37dec4afe984834ae09 100644 --- a/src/macosx/native/sun/awt/CFRetainedResource.m +++ b/src/macosx/native/sun/awt/CFRetainedResource.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,10 +40,17 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CFRetainedResource_nativeCFRelease if (releaseOnAppKitThread) { // Releasing resources on the main AppKit message loop only // Releasing resources on the nested loops may cause dangling - // pointers after the nested loop is exited - [NSApp postRunnableEvent:^(){ - CFRelease(jlong_to_ptr(ptr)); - }]; + // pointers after the nested loop is exited + if ([NSApp respondsToSelector:@selector(postRunnableEvent:)]) { + [NSApp postRunnableEvent:^() { + CFRelease(jlong_to_ptr(ptr)); + }]; + } else { + // could happen if we are embedded inside SWT/FX application, + [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() { + CFRelease(jlong_to_ptr(ptr)); + }]; + } } else { JNF_COCOA_ENTER(env);