I am disinfecting my xml in an async task. In a particular case, I go out of memory when deserializing. I know that there is a flag under the name largeHeap, which I can use in your application. But is there any way to find out what exactly to avoid in this place.
According to my finding is System.gc()not the best solution to fix it. Can anyone help me through this. The following is a snippet of code.
private HashMap<String, Game> games = new HashMap<String, Game>();
public void load(LocalDatabaseHelper localDbHelper) throws Exception
{
synchronized(gameLockObject) {
GameDetailDAO dao = new GameDetailDAO(localDbHelper);
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);
}
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()));
}
games.put(gameDetail.getGameRef().toLowerCase(Locale.getDefault()), game);
}
}
}
source
share