Android缓存后台进程不断增加 [英] Android cache background process is increasing continuously

查看:337
本文介绍了Android缓存后台进程不断增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在名为"PriceDekho"的android应用程序中,缓存后台进程占用了太多空间. 首先,当我启动应用程序时,该应用程序占用了大约30MB的空间(我认为这样还可以),但问题是,当我浏览应用程序页面时,此大小不断增加,直至达到(200 MB).此应用程序缓存后台进程"也随移动RAM大小而变化.如果移动RAM的大小为2GB,则此应用程序缓存后台进程"的大小将增加到500至700 MB.

我的应用程序只有5到6个屏幕.我只需要稳定缓存的背景大小即可.

如何清除应用程序缓存的大小?请帮忙.

解决方案

听起来您的内存泄漏是垃圾回收器无法删除的.例如,如果您需要从非上下文类中引用Context,该类从未在那里发布.大多数时候,Android Studio会指出这些问题,但是您可以尝试使用 LeakCanary 并进行搜索. /p>

添加依赖项

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

并在您的Application类中使用它.如果还没有,请创建一个.

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...
  }
}

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.

解决方案

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...
  }
}

这篇关于Android缓存后台进程不断增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆