FoxMulder900
Lurker
I am working on a small game where I want a loading screen to appear when loading the next level. I have accomplished this using an AsycTask, the idea being that I draw the loading screen first and call invalidate(), then I start an AsyncTask which loads a new map object in the background so that the UI thread can continue and draw the loading screen. When complete, the map is returned and the loading screen is removed.
This works, however; the Map object which i create in doInBackground seems to persist, so after the 4th level, even though I only have references to 1 Map, I have 4 Map objects in memory (I got this information by doing a heap dump after each level load). At this point I get an OutOfMemoryError.
Something else to note is that after the 4th level load, under the Threads tab in the DDMS i see:
AsyncTask#1
AsyncTask#2
AsyncTask#3
AsyncTask#4
all with a status of "wait"
Any ideas here would be greatly appreciated!
Code:
public class LoadTask extends AsyncTask<String,Integer,Map>{
protected Map doInBackground(String... mapName) {
return new Map(mapName[0]);
}
protected void onPostExecute(Map newMap) {
//Set newMap as active Map
//Remove loading screen and draw newMap
}
}
//Draw Loading Screen
//Call invalidate
//Execute a LoadTask to that UI thread can continue to draw loading screen
new LoadTask().execute(mapName);
This works, however; the Map object which i create in doInBackground seems to persist, so after the 4th level, even though I only have references to 1 Map, I have 4 Map objects in memory (I got this information by doing a heap dump after each level load). At this point I get an OutOfMemoryError.
Something else to note is that after the 4th level load, under the Threads tab in the DDMS i see:
AsyncTask#1
AsyncTask#2
AsyncTask#3
AsyncTask#4
all with a status of "wait"
Any ideas here would be greatly appreciated!