Here to cite an article, http://blog.csdn.net/editor1994/article/details/50394560 a very good analysis of the oom problem
A large number of images loaded in the project were not released after use, resulting in memory leaks, until oom, later I use the above article used to find that the method is effective, but in an interface multiple frequent or will appear, so helpless can only change the glide picture loading frame,
Customizing a Glidemodule,
1 /**2 * Created by admin on 2017/4/7.3 */4 5 Public classGlidedemoImplementsGlidemodule {6 @Override7 Public voidapplyoptions (context context, Glidebuilder Builder) {8Builder.setmemorycache (NewLruresourcecache (2*1024*1024));9Builder.setbitmappool (NewLrubitmappool (2*1024*1024));Ten } One A @Override - Public voidregistercomponents (Context context, Glide Glide) { - the } -}
The code when loading the picture
1 Glide.with (lyactivity. This)2 . Load (arraylist.get (position). GETBIGIMG ())3 . Error (r.drawable.mimg) 4 . Skipmemorycache (false)5 . Diskcachestrategy (Diskcachestrategy.all) 6 . into (Mimage);
At present the problem is solved, follow-up in addition, and start a server, real-time monitoring memory usage, if the memory is about to exceed the specified memory, forced to return to the home page and release resources
Service code for monitoring memory
1Timer =NewTimer ();2TimerTask =NewTimerTask () {3 @Override4 Public voidrun () {5 //Maximum available memory for the application6 intMaxMemory = ((int) Runtime.getruntime (). MaxMemory ())/1024/1024;7 //application has acquired memory8 LongTotalMemory = ((int) Runtime.getruntime (). TotalMemory ())/1024/1024;9 //application has acquired unused memory in memoryTen LongFreememory = ((int) Runtime.getruntime (). Freememory ())/1024/1024; OneSYSOUT.PRINTLN ("I---> Application memory =" +maxmemory+ "m, and used =" +totalmemory+ "m, remainder =" +freememory+ "M"); A if(TotalMemory > 58){ - //Toast.maketext (neicunservice.this, "program exception, restarting, please later", Toast.length_short). Show (); -Context.sendbroadcast (NewIntent ("Com.zhushiyun.oom")); the //system.exit (0); - //Timer.cancel (); - } - } + }; -Timer.schedule (timertask,1000,5000); +Sysout.println ("I am monitoring the content of I have started");
Android Learning notes-using Universal-image-loaderf to solve oom problems