So this is just a habit of mine, whenever a game loop is cancel I usually running a destroy() functions that will clear all List, ArrayList, HashMap, HashSet and so on. Before setting them to null.
A typical destroy function I write looks like this
public static void destroy(){
System.out.println("Clearing chunks and entities.");
for(World w : worlds){
w.entityList.clear();
w.entityList = null;
w.chunks.clear();
w.chunks = null;
}
System.out.println("Clearing worlds.");
worlds.clear();
worlds = null;
}
Then when everything is done I usually run one System.gc just before running System.exit. But I have heard that System.gc should be avoided, and I was wondering is it so bad to run it once before exit the game?