Android Memory Detection

Source: Internet
Author: User

 /** * Turn on the thread detection software available memory condition, after the software exits, call System.exit (0) The thread will stop * * * @param sleep * Detect memory every time * @pa    RAM Standard * Memory over how many proportional alarms */public static void Memorywatch (final int sleep, Final int. standard)            {if (sleep <= 0) {log.e (TAG, "memorywatch, invalid sleep = 0!");        Return } if (standard <= 0 && standard > +) {log.e (TAG, "Memorywatch, invalid standard            Percent = "+ standard";        Return                } New Thread (new Runnable () {@Override public void run () {                LOG.D (TAG, "Memorywatch, start thread!");                    while (true) {long divisor = 1024 * 1024;                    Long MaxMem = Runtime.getruntime (). MaxMemory ();                    Long Totalmem = Runtime.getruntime (). TotalMemory (); Long Freemem = Runtime.getruntime (). Freememory ();                    int percent = (int) (TOTALMEM * 100/maxmem);  LOG.D (TAG, "Memorywatch" + ", app MaxMem =" + Maxmem/divisor + "M, Totalmem =" + Totalmem/ Divisor + "m, Freemem =" + Freemem/divisor + "m, percent =" + P                    ercent);                        If (standard <= percent) {if (Freemem/divisor <= 2) {LOG.E (TAG, "Memorywatch" + ", app MaxMem =" + MaxMem                                    /divisor + "m, Totalmem =" + Totalmem/divisor + "m, Freemem ="                        + Freemem/divisor + "M, percent =" + percent);                            } else if (Freemem/divisor >= totalmem/(DIVISOR * 2)) { LOG.E (TAG, "MemoRywatch "+", app MaxMem = "+ Maxmem/divisor +" M, Totalmem = "  + Totalmem/divisor + "m, Freemem =" + Freemem/divisor + "m, percent = "+ percent +"% "+", reset memory warn flag = t                    Rue! ");}}                    try {thread.sleep (sleep); } catch (Interruptedexception e) {log.e (TAG, "Memorywatch, T                    Hread Sleep Exception: "+ E);    }}}). Start (); }

Android Memory Detection

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.