OOME guard
authorAlexey Kudravtsev <cdr@intellij.com>
Wed, 7 Jul 2010 12:47:06 +0000 (16:47 +0400)
committerAlexey Kudravtsev <cdr@intellij.com>
Fri, 9 Jul 2010 09:44:42 +0000 (13:44 +0400)
platform/util/testSrc/com/intellij/util/containers/WeaksTestCase.java

index 9d88ab2989ab4670e663f537ebf097e4c9af664a..6f426d0e7a1626966f9e99ad418be99f1ccab10c 100644 (file)
@@ -45,13 +45,18 @@ public abstract class WeaksTestCase extends TestCase {
 
   protected static void gc() {
     System.gc();
-    List<Object> list = new ArrayList<Object>();
-    while (Runtime.getRuntime().freeMemory() > 10000) {
-      list.add(new byte[1000]);
-    }
+    try {
+      List<Object> list = new ArrayList<Object>();
+      while (Runtime.getRuntime().freeMemory() > 10000) {
+        list.add(new byte[1000]);
+      }
 
-    System.gc();
-    list = null;
+      System.gc();
+      list = null;
+    }
+    catch (OutOfMemoryError e) {
+      // ignore
+    }
     System.gc();
 
     WeakReference<Object> weakReference = new WeakReference<Object>(new Object());