#82808: Don't keep (unnecessary) implicit reference to the scheduled task, we only need the item reference.
1.1 --- a/openide.util/src/org/openide/util/RequestProcessor.java Wed Aug 16 06:28:12 2006 +0000
1.2 +++ b/openide.util/src/org/openide/util/RequestProcessor.java Wed Aug 16 13:27:52 2006 +0000
1.3 @@ -486,6 +486,22 @@
1.4 }
1.5 }
1.6
1.7 + private class EnqueueTask extends TimerTask {
1.8 + Item itm;
1.9 +
1.10 + EnqueueTask(Item itm) {
1.11 + this.itm = itm;
1.12 + }
1.13 +
1.14 + public void run() {
1.15 + try {
1.16 + enqueue(itm);
1.17 + } catch (RuntimeException e) {
1.18 + Exceptions.printStackTrace(e);
1.19 + }
1.20 + }
1.21 + }
1.22 +
1.23 /**
1.24 * The task describing the request sent to the processor.
1.25 * Cancellable since 4.1.
1.26 @@ -582,17 +598,7 @@
1.27 if (delay == 0) { // Place it to pending queue immediatelly
1.28 enqueue(localItem);
1.29 } else { // Post the starter
1.30 - starterThread.schedule(new TimerTask() {
1.31 -
1.32 - public void run() {
1.33 - try {
1.34 - enqueue(localItem);
1.35 - }
1.36 - catch (RuntimeException e) {
1.37 - Exceptions.printStackTrace(e);
1.38 - }
1.39 - }
1.40 - }, delay);
1.41 + starterThread.schedule(new EnqueueTask(localItem), delay);
1.42 }
1.43 }
1.44
2.1 --- a/openide.util/test/unit/src/org/openide/util/RequestProcessorTest.java Wed Aug 16 06:28:12 2006 +0000
2.2 +++ b/openide.util/test/unit/src/org/openide/util/RequestProcessorTest.java Wed Aug 16 13:27:52 2006 +0000
2.3 @@ -117,6 +117,32 @@
2.4
2.5 }
2.6
2.7 + public void testTaskLeakWhenCancelled() throws Exception {
2.8 + Runnable r = new Runnable() {public void run() {}};
2.9 +
2.10 + // schedule (1hour) and cancel immediatelly
2.11 + new RequestProcessor(getName()).post(r, 3600*1000).cancel();
2.12 +
2.13 + WeakReference wr = new WeakReference(r);
2.14 + r = null;
2.15 + assertGC("runnable should be collected", wr);
2.16 + }
2.17 +
2.18 + /* This might be issue as well, but taking into account the typical lifecycle
2.19 + of a RP and its size, I won't invest in fixing this now.
2.20 + *//*
2.21 + public void testRPLeakWhenLastTaskCancelled() throws Exception {
2.22 + Runnable r = new Runnable() {public void run() {}};
2.23 +
2.24 + // schedule (1hour) and cancel immediatelly
2.25 + RequestProcessor rp = new RequestProcessor(getName());
2.26 + rp.post(r, 3600*1000).cancel();
2.27 +
2.28 + WeakReference wr = new WeakReference(rp);
2.29 + rp = null;
2.30 + assertGC("runnable should be collected", wr);
2.31 + } /**/
2.32 +
2.33 public void testScheduleAndIsFinished() throws InterruptedException {
2.34 class Run implements Runnable {
2.35 public boolean run;