summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java1
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java22
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java30
3 files changed, 31 insertions, 22 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java
index 547269edac..622f7e2870 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java
@@ -195,6 +195,7 @@ protected void create(DeviceData deviceData) {
NSAutoreleasePool pool = null;
if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
try {
+ NSApplication.sharedApplication();
data = (PrinterData)deviceData;
if (data.otherData != null) {
NSData nsData = NSData.dataWithBytes(data.otherData, data.otherData.length);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java
index b5d05cfa43..0d6b776745 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java
@@ -113,16 +113,18 @@ public Device(DeviceData data) {
objects = new Object [128];
trackingLock = new Object ();
}
- NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- NSThread nsthread = NSThread.currentThread();
- NSMutableDictionary dictionary = nsthread.threadDictionary();
- NSString key = NSString.stringWith("SWT_NSAutoreleasePool");
- id obj = dictionary.objectForKey(key);
- if (obj == null) {
- NSNumber nsnumber = NSNumber.numberWithInteger(pool.id);
- dictionary.setObject(nsnumber, key);
- } else {
- pool.release();
+ if (NSThread.isMainThread()) {
+ NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
+ NSThread nsthread = NSThread.currentThread();
+ NSMutableDictionary dictionary = nsthread.threadDictionary();
+ NSString key = NSString.stringWith("SWT_NSAutoreleasePool");
+ id obj = dictionary.objectForKey(key);
+ if (obj == null) {
+ NSNumber nsnumber = NSNumber.numberWithInteger(pool.id);
+ dictionary.setObject(nsnumber, key);
+ } else {
+ pool.release();
+ }
}
//check and create pool
create (data);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
index 45ce432787..2a811d90f9 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
@@ -456,6 +456,10 @@ void addPool (NSAutoreleasePool pool) {
System.arraycopy (pools, 0, temp, 0, poolCount);
pools = temp;
}
+ if (poolCount == 0) {
+ NSMutableDictionary dictionary = NSThread.currentThread().threadDictionary();
+ dictionary.setObject(NSNumber.numberWithInteger(pool.id), NSString.stringWith("SWT_NSAutoreleasePool"));
+ }
pools [poolCount++] = pool;
}
@@ -681,7 +685,7 @@ void clearModal (Shell shell) {
}
void clearPool () {
- if (sendEventCount == 0 && loopCount == poolCount - 1) {
+ if (sendEventCount == 0 && loopCount == poolCount - 1 && Callback.getEntryCount () == 0) {
removePool ();
addPool ();
}
@@ -923,15 +927,6 @@ protected void destroy () {
}
void destroyDisplay () {
-
- Runtime.getRuntime().addShutdownHook(new Thread() {
- // Any top-level autorelease pool cannot be destroyed until the absolute end of the application.
- // terminate is that absolute end of the app; it will also clean up any remaining pools.
- public void run() {
- NSApplication.sharedApplication().terminate(null);
- }
- });
-
application = null;
}
@@ -1873,6 +1868,13 @@ protected void init () {
if (!Display.launched) {
application.finishLaunching();
Display.launched = true;
+
+ /* only add the shutdown hook once */
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ NSApplication.sharedApplication().terminate(null);
+ }
+ });
}
}
@@ -3080,7 +3082,7 @@ int /*long*/ observerProc (int /*long*/ observer, int /*long*/ activity, int /*l
*/
public boolean readAndDispatch () {
checkDevice ();
- if (sendEventCount == 0 && loopCount == poolCount - 1) removePool ();
+ if (sendEventCount == 0 && loopCount == poolCount - 1 && Callback.getEntryCount () == 0) removePool ();
addPool ();
loopCount++;
boolean events = false;
@@ -3102,7 +3104,7 @@ public boolean readAndDispatch () {
} finally {
removePool ();
loopCount--;
- if (sendEventCount == 0 && loopCount == poolCount) addPool ();
+ if (sendEventCount == 0 && loopCount == poolCount && Callback.getEntryCount () == 0) addPool ();
}
return events;
}
@@ -3382,6 +3384,10 @@ void removeMenu (Menu menu) {
void removePool () {
NSAutoreleasePool pool = pools [poolCount - 1];
pools [--poolCount] = null;
+ if (poolCount == 0) {
+ NSMutableDictionary dictionary = NSThread.currentThread().threadDictionary();
+ dictionary.removeObjectForKey(NSString.stringWith("SWT_NSAutoreleasePool"));
+ }
pool.release ();
}