Will the previous world be garbage collected once I instantiate a new world. Example: I have a world "Intro" and instantiate a world "Map", will Intro still be active?


import greenfoot.*; public class Map extends World { private static Map mapInstance; private Map() { super(600, 400, 1); // ... } // return the current Map instance, if exists; if not, create and return one public static Map getMap() { if (mapInstance == null) mapInstance = new Map(); return(mapInstance); } // return a new Map instance public static Map getNewMap() { mapInstance = null; return getMap(); } // ... }
/** from another class */ // getting the current map Map map = Map.getMap(); // or // creating a new map Map map = Map.getNewMap();