Author: allain.lalonde
Date: Fri Jul 17 17:35:13 2009
New Revision: 498

Added:
     
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingCanvasTest.java

Log:
Added PSwingCanvas Test for Memory Leak

Added:  
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingCanvasTest.java
==============================================================================
--- (empty file)
+++  
piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingCanvasTest.java
       
Fri Jul 17 17:35:13 2009
@@ -0,0 +1,30 @@
+package edu.umd.cs.piccolox.pswing;
+
+import javax.swing.JPanel;
+
+import edu.umd.cs.piccolo.PCanvas;
+import junit.framework.TestCase;
+
+public class PSwingCanvasTest extends TestCase {
+    protected int pCanvasFinalizerCount;
+
+    public void testMemoryLeakWithPCanvas() throws InterruptedException {
+        JPanel panel = new JPanel();
+        for (int i=0; i < 10; i++) {
+            PSwingCanvas canvas = new PSwingCanvas() {
+                public void finalize() {
+                    pCanvasFinalizerCount ++;
+                }
+            };
+            panel.add(canvas);
+            panel.remove(canvas);
+            canvas = null;
+        }
+
+        System.gc();
+        System.runFinalization();
+
+        // Not sure why I need -1 here, but I do. If I create 10000 it'll  
always be 1 less
+        assertEquals(10-1, pCanvasFinalizerCount);
+    }
+}

--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to