Android Learning notes-using Universal-image-loaderf to solve oom problems

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.