Android cache background process is increasing continuously

14,568

Solution 1

It sounds like you have memory leaks which the Garbage Collector can not remove. For example if you need to have a reference to the Context from a non-context class which is never released there. Most of the time Android Studio will point those out but you can try to use LeakCanary and search for them.

Add the dependency

dependencies {
   debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
 }

and use it in your Application class. Create one if you don't have it already.

public class ExampleApplication extends Application {

  @Override public void onCreate() {
    super.onCreate();
    if (LeakCanary.isInAnalyzerProcess(this)) {
      // This process is dedicated to LeakCanary for heap analysis.
      // You should not init your app in this process.
      return;
    }
    LeakCanary.install(this);
    // Normal app init code...
  }
}

Solution 2

Cache background process surely varies with the RAM size as the system will allow more data to be cached if more memory is available.

However, the increasing pattern in memory usage by the application may either be due to memory leaks or huge objects being created in the background. The Garbage collector is not an all weather friend and may tend to ignore memory leaks due to programmatic mistakes.

As there is no code posted for review, some trivial questions to ask would be:

  • Is there a lot of image processing being done using bitmaps? If yes, are those bitmaps being recycled ?

  • Is your application using the context judiciously, that is avoiding usage of the application context, unless required ?

  • Are the listeners being unregistered, if any ?

    As suggested above, LeakCanary will surely be much useful in this case, surely more than the Android Monitor.

Share:
14,568

Related videos on Youtube

Manish Agrawal
Author by

Manish Agrawal

Updated on July 09, 2022

Comments

  • Manish Agrawal
    Manish Agrawal almost 2 years

    In my android application named "PriceDekho" the cache background process takes too much space. First when i start the application the application takes arround 30MB (I think its OK) but the problem is when i surfing the application pages then this size is increasing continuously upto (200 MB). This appliction "Cache background process" also varying with the mobile RAM size. If the mobile RAM size is 2GB then this application "Cache background process" size goes upto 500 to 700 MB.

    My application is having only 5 to 6 screens. I just need to stabilize the cached background size.

    How can i clear the application cached size? Please help.

    enter image description here

    enter image description here