Android的可绘制内存泄漏 [英] Android Drawables memory leak
问题描述
我跟几个大可绘制工作,我不知道如何管理内存泄漏。 我找到我的应用程序的堆大小和它不会停止增长(如已分配的内存)。
I work with several large drawables and I don't know how to manage memory leaks. I tracked the heap size of my application and it doesn't stop to grow (as the allocated memory).
这是特别的字节数组(字节[])类型,它长大,从来没有下降。 (在Eclipse中的DDMS堆视图)
It is especially the "byte array (byte[])" type which grows up and never decrease. (in the DDMS Heap view on Eclipse)
我的应用程序由一个活动,它使用的片段。 这些片段显示几个大的图像。 我试图设置可绘制回调为空,设置可绘为null,清楚我的性高速缓存(其中prevent我的应用程序从做过多的磁盘IO),当我弹回的片段,但堆从未减少。
My application is composed of one activity which uses fragments. Those fragments are displaying several large images. I tried to set drawables callback to null, set drawables to null, clear my volatile cache (which prevent my app from doing too many disk IO) when I pop back a fragment but the heap never decrease.
其实,每次我打电话: Drawable.createFromResourceStream(context.getResources(),价值,新的FileInputStream(F),f.getName(),选择采用); 堆长大。我该如何释放内存?
In fact, each time I call : Drawable.createFromResourceStream(context.getResources(), value, new FileInputStream(f), f.getName(), opts); the heap grows up. How can I free memory ?
谢谢!
推荐答案
一个内存泄漏发生时,java中是$ P $从释放该内存pventing垃圾收集器由您的code引用的内存查找对象。在Android的一个常见原因是引用的活动范围内,而不是应用程序上下文。确保你的背景下引用的应用程序(即使用 getApplicationContext
而不是使用这
。检查此的视频的解释内存泄漏,并检查该的question 。
A memory leak happens when Java finds objects in the memory that are referenced by your code which is preventing the Garbage Collector from freeing this memory. A common cause in Android is referencing the Activity context rather than the Application context. Make sure your context references the Application (i.e. use getApplicationContext
rather than using this
. Check this video for explanation on Memory leaks and also check this question.
这篇关于Android的可绘制内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!