Android 位图内存使用
我正在运行一堆图像过滤器,似乎遇到了一些内存问题。
在图像处理开始时,我使用了这么多内存:
GC_FOR_MALLOC freed 3K, 45% free 3237K/5831K, external 47586K/49634K, paused 17ms
最后我使用了这么多内存(在所有处理完成之后):
GC_EXTERNAL_ALLOC freed 5K, 16% free 16056K/18951K, external 51430K/52196K, paused 23ms
完成每个位图后,我将其设置为回收并设置为空:
someBitmap.recycle();
someBitmap = null;
还有其他吗我应该对他们做什么?我应该对正在使用的画布进行任何清理吗?
另外,我的过滤器是实例化的对象,例如:
BoxBlurFilter blurFilter = new BoxBlurFilter();
我应该做什么来释放它们?在用“new”分配的iOS内存中,我负责释放。
对于一些琐碎的内存管理问题,我深表歉意,但我对 Android 开发还很陌生,事情与 iOS 有很大不同。
谢谢你!
编辑2,我删除了完整的过滤器代码。
I am running a stack of image filters and seem to be hitting some memory issues.
At the beginning of the image processing I am using this much memory:
GC_FOR_MALLOC freed 3K, 45% free 3237K/5831K, external 47586K/49634K, paused 17ms
At the end I am using this much (after all processing is finished):
GC_EXTERNAL_ALLOC freed 5K, 16% free 16056K/18951K, external 51430K/52196K, paused 23ms
After I am finished with each bitmap I set it to recycle and to null:
someBitmap.recycle();
someBitmap = null;
Is there anything else I should be doing to them? Is there any cleanup I should do to the Canvas being used?
Also my filters are objects instantiated like:
BoxBlurFilter blurFilter = new BoxBlurFilter();
Is there anything I should do to release them? In iOS memory allocated with "new" I am responsible to free.
Sorry for the trivial memory management questions, but I am quite new to Android dev and things are quite different than iOS.
Thank you!
EDIT 2, I removed my full filter code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,在将过滤器实例设置为 null 并将所有字节数组设置为 null(在上面的代码和过滤器对象中)之后,我现在的堆大小与运行过滤器之前的堆大小大致相同:
这意味着它从 16mb 变为习惯了3.2mb。好多了!
所以我想我的问题的答案是,如果您希望释放它,请确保将所有内容设置为空。
So after setting the filter instances to null and all the byte arrays to null (in the code above and in the filter objects) I now have approximately the same size heap as I did before I run the filter:
That means it went from 16mb being used to 3.2mb. Much better!
So I guess the answer to my question is make sure you set everything to null if you want it to be freed.