android - Out of memory during XML deserialisation -
i de - serializing xml in async task. @ particular instance getting out of memory error while de- serialization. know there flag called largeheap
can use in application. there way find out avoid @ place.
as per finding system.gc()
not best solution fix it. can me through it. below 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 fetch me entities databse arraylist<gamedetailentity> dbgamedetails = dao.getentities(null, null); (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 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 job store games.put(gamedetail.getgameref().tolowercase(locale.getdefault()), game); } } }
the problem not specific code in app, basic design. have data you're trying handle @ once.
do not serialize data (and not use xml; i'd guess not require markup begin with).
instead, store data of games in normalized database (i.e., use tables/columns everything). not load @ once, load as need.
Comments
Post a Comment