Skip to content

Instantly share code, notes, and snippets.

@jnorthrup
Created November 1, 2012 20:24
Show Gist options
  • Save jnorthrup/3996244 to your computer and use it in GitHub Desktop.
Save jnorthrup/3996244 to your computer and use it in GitHub Desktop.
/**
* might avoid growing heap, swapping heap, etc. and likely to constantly trigger gc in gwtc.
*/
static {
String wantHeadroom = System.getProperty("wantHeadroom","");
if(!wantHeadroom.isEmpty())
new Timer().scheduleAtFixedRate(new TimerTask() {
private Runtime runtime = Runtime.getRuntime();
@Override
public void run() {
long l = runtime.freeMemory();
long l1 = runtime.totalMemory();
if(.2f*l1>l)
System.gc();
}
}, 1000,1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment