I am de - serializing my xml in async task. At some particular instance I am getting out of memory error while de- serialization. I know there is a flag called largeHeap
which I can use in my application. But is there any way to find out specifically avoid at that place.
As per my finding System.gc()
is not probably a best solution to fix it. Can anybody help me through it. Below is the code snippet.
private HashMap<String, Game> games = new HashMap<String, Game>();
public void load(LocalDatabaseHelper localDbHelper) throws Exception
{
synchronized(gameLockObject) {
GameDetailDAO dao = new GameDetailDAO(localDbHelper);
//this will fetch me the all the entities from databse
ArrayList<GameDetailEntity> dbGameDetails = dao.getEntities(null, null);
for (GameDetailEntity gameDetail : dbGameDetails) {
String gameLevel = gameDetail.getDetailLevel();
String gameXml = gameDetail.getGameData();
Game game = null;
if(gameLevel.equalsIgnoreCase("Novice")) {
game = Job.deserialiseJob(gameXml, NoviceLevel.class);
}
else if (gameLevel.equalsIgnoreCase("Expert")) {
game = Job.deserialiseJob(gameXml, ExpertLevel.class);
}
//set the job version
game.setGameversion(gameDetail.getGameVersion());
game.setMagicNumber(gameDetail.getMagicNumber());
game.setInactiveUser(gameDetail.getInactiveUser());
game.setStartTime(gameDetail.getStartTime());
game.setFinishTime(gameDetail.getFinishTime());
game.setGameCompletionTime(gameDetail.getGameCompletionTime());
if (!StringUtils.isNullOrEmpty(gameDetail.getGameStatus())) {
game.setGameStatus(GameStatus.valueOf(gameDetail.getGameStatus()));
}
//add the job to the store
games.put(gameDetail.getGameRef().toLowerCase(Locale.getDefault()), game);
}
}
}