Fixed memory leak by forcing garbage collection

This commit is contained in:
Michael Rausch
2017-09-28 14:22:33 +13:00
parent 9795083d4d
commit 3345734efd
2 changed files with 21 additions and 1 deletions
+14
View File
@@ -13,6 +13,9 @@ import org.slf4j.LoggerFactory;
import seng302.discoveryServer.DiscoveryServer; import seng302.discoveryServer.DiscoveryServer;
import seng302.visualiser.controllers.ViewManager; import seng302.visualiser.controllers.ViewManager;
import java.util.Timer;
import java.util.TimerTask;
public class App extends Application { public class App extends Application {
private static Logger logger = LoggerFactory.getLogger(App.class); private static Logger logger = LoggerFactory.getLogger(App.class);
@@ -92,6 +95,17 @@ public class App extends Application {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
/*
* Do not trust Java to do garbage collection
*/
new Timer().schedule(new TimerTask() {
@Override
public void run() {
System.gc();
}
}, 0, 1200);
try { try {
parseArgs(args); parseArgs(args);
} catch (ParseException e) { } catch (ParseException e) {
@@ -158,7 +158,13 @@ public abstract class Message {
* @return The current buffer as a byte array * @return The current buffer as a byte array
*/ */
public byte[] getBuffer(){ public byte[] getBuffer(){
return buffer.array(); byte[] bytes = buffer.array();
// buffer.reset();
// buffer.clear();
// buffer = null;
return bytes;
} }
/** /**