If you are writing memory consuming applications there is a bigger chance that your application may be running out of memory after sometime. So there are some methods in android that invokes the garbage collector explicitly.

See the following function which invokes the garbage collector to free a lot of memory.

public void freeMemory(){		
    System.runFinalization();
    Runtime.getRuntime().gc();
    System.gc();
}

A little explanation about the methods.

Java.Lang.Runtime.RunFinalization Method
Provides a hint to the VM that it would be useful to attempt to perform any outstanding object finalization.

Both System.gc() is effectively equivalent to Runtime.gc(). System.gc() internally calls Runtime.gc().
The only diff is System.gc() is a class method where as Runtime.gc() is an instance method. So, System.gc() is more convenient.

 

One Comment

  1. casio edifice 価格 November 4, 2013 at 1:43 am

    seiko カタログ

     

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.