tags:

views:

75

answers:

2

Hi Friends,

I want to clear catch memory when I close my application in Android. A code example would be helpful.

Thanks

A: 

something like this should do the trick, although this example has no error handling you will want to add that.

   public void clearCache() {
    Log.i(TAG, "Clearing Cache.");
    File[] dir = mContext.getCacheDir().listFiles();
    if(dir != null){
        for (File f : dir){
            f.delete();
        }
       }
    }
schwiz
@Hi schwiz,i am fresher in android,so can u tell where can i use this method in application
sivaraj
you can call getChacheDir anywhere that you have a reference to the application context, usually in an Activity or a Service.
schwiz
Thanks it is working
sivaraj
A: 

Actually you cann't really close your application since Android takes care about the process lifetimes.

And if you're talking about RAM there is also no need to free unused memory because Android manages the memory as well.

Martin
He is talking about the cache on the system disk that things like using a webview leave behind.
schwiz