From 2641a2fa3ea967d225e444a33cde8d1f77796894 Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Sat, 12 Oct 2013 11:09:42 +0530 Subject: [PATCH] Trying to solve the permgen out of memory problem --- pdex/Todo, GSoC 2013.txt | 4 ++++ .../experimental/ErrorCheckerService.java | 22 ++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pdex/Todo, GSoC 2013.txt b/pdex/Todo, GSoC 2013.txt index cdd5026ba..d2e577745 100644 --- a/pdex/Todo, GSoC 2013.txt +++ b/pdex/Todo, GSoC 2013.txt @@ -150,6 +150,10 @@ x boolean warningsEnabled - made it volatile General Stuff ============= +* [Critical] PermGen out of memory bug. Manually triggering GC after making the classloader null ensures permgen memory is reclaimed on editor exit. Max open window still limited by max permgen size. Also, added a classloadcounter in ECS to trigger GC periodically. +https://github.com/processing/processing-experimental/issues/1 +See: http://stackoverflow.com/questions/2095974/how-to-unload-a-already-loaded-class-in-java +I'm making the classLoader null, but what about the classes loaded by ASTGen? Investigate. x Disabling Error Checking disables predictions as well! Fixed. x Added doc listener for text area updates x Consult Ben on where to save preferences - main preferences.txt or custom one. - Main prefs file diff --git a/pdex/src/processing/mode/experimental/ErrorCheckerService.java b/pdex/src/processing/mode/experimental/ErrorCheckerService.java index 0b509c191..62ccf3ae4 100644 --- a/pdex/src/processing/mode/experimental/ErrorCheckerService.java +++ b/pdex/src/processing/mode/experimental/ErrorCheckerService.java @@ -292,10 +292,14 @@ public class ErrorCheckerService implements Runnable{ checkCode(); checkForMissingImports(); } - checkerClass = null; + astGenerator.disposeAllWindows(); - astGenerator = null; + compilationChecker = null; + checkerClass = null; + classLoader = null; + System.gc(); logE("Thread stopped: " + editor.getSketch().getName()); + System.gc(); } protected void updateSketchCodeListeners() { @@ -558,7 +562,11 @@ public class ErrorCheckerService implements Runnable{ for (int i = 0; i < jarFiles.length; i++) { classpath[ii++] = jarFiles[i].toURI().toURL(); } - + + compilationChecker = null; + checkerClass = null; + classLoader = null; + System.gc(); // log("CP Len -- " + classpath.length); classLoader = new URLClassLoader(classpath); // log("1."); @@ -650,7 +658,15 @@ public class ErrorCheckerService implements Runnable{ // log("Compilecheck, Done."); } + private int loadClassCounter = 0; public URLClassLoader getSketchClassLoader() { + loadClassCounter++; + if(loadClassCounter > 100){ + loadClassCounter = 0; + classLoader = null; + System.gc(); + classLoader = new URLClassLoader(classpath); + } return classLoader; }