Permalink
Browse files

Improvements to MemoryMaid watch dog

  • Loading branch information...
1 parent f0c25e4 commit ed8a08f6bd945b5886a6582281bf5dcee83cc18d @qingbiao qingbiao committed Dec 12, 2011
@@ -35,6 +35,7 @@ public Object execute( Object thiz, Object[] args ) {
static class ExitRunner implements Runnable {
public void run() {
+ System.gc(); // MemoryMaid
System.exit( 0 );
}
}
@@ -23,7 +23,7 @@
*/
public class MemoryMaid extends Thread {
protected final static int LOWMEM_THRESHHOLD = 1024 * 1024 * 5; // 5Mb
- protected final static float DEVIATION_THRESHHOLD = 0.05f; // 5%
+ protected final static float DEVIATION_THRESHHOLD = 0.10f; // 10%
protected final static long GC_TIMEOUT = 25000; // Wait time after a gc. To avoid calling gc too much
protected final static long SAMPLE_RATE = 5000; // How often to check memory
@@ -110,4 +110,6 @@ public void stop() {
public void flagGC() {
_doGC = true;
}
+
+
}
@@ -143,11 +143,10 @@ public static void main( String[] args ) {
waitForStartupComplete();
}
Widget widget = makeWidget( args, wConfig );
- MemoryMaid mm = MemoryMaid.getInstance();
- if( mm != null ) {
- mm.start();
- }
+
widget.enterEventDispatcher();
+
+ MemoryMaid mm = MemoryMaid.getInstance();
if( mm != null ) {
mm.stop();
}
@@ -48,6 +48,7 @@ public boolean onClose() {
if( EventService.getInstance().fireEvent(ApplicationEventHandler.EVT_APP_EXIT, null, true) ) {
return false;
}
+ System.gc(); // MemoryMaid
// Do not call the default onClose function so the save dialog is skipped.
close();
return true;
@@ -154,19 +154,23 @@ public void handleNavigationRequest( BrowserFieldRequest request ) throws Except
throw e;
}
}
+
+ MemoryMaid mm = MemoryMaid.getInstance();
+ if( mm != null ) {
+ if( mm.isAlive() ) {
+ mm.flagGC();
+ } else {
+ // Start the memory manager after our first page has been loaded
+ mm.start();
+ }
+ }
}
/**
* @see net.rim.device.api.browser.field2.BrowserFieldController
*/
public InputConnection handleResourceRequest( BrowserFieldRequest request ) throws Exception {
- // Clean up memory
- MemoryMaid mm = MemoryMaid.getInstance();
- if( mm != null && mm.isAlive() ) {
- mm.flagGC();
- }
-
if( this._browserField == null ) {
return new HTTPResponseStatus( HTTPResponseStatus.SC_SERVER_ERROR, request ).getResponse();
}

0 comments on commit ed8a08f

Please sign in to comment.