Android缓存后台进程不断增加

编程入门 行业动态 更新时间:2024-10-28 12:17:58
本文介绍了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缓存后台进程不断增加

本文发布于:2023-10-28 13:56:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536822.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   后台   进程   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!