机器人:largeHeap ="真"公约? [英] android:largeHeap="true" convention?

查看:117
本文介绍了机器人:largeHeap ="真"公约?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个图片库的应用程序,我一直运行到内存不足的错误。我缓存我所有的照片,但当我尝试图片之间的切换出现问题的真快。我假设应用程序的速度比GC有时间来释放他们,(因为当我切换图像慢慢的崩溃不会发生)分配内存。

敲我的头这问题好几天后,我终于决定给largeHeap设置在清单文件一试。此设置后,我的应用程序不再崩溃,不管我的图像之间的速度切换。

现在,我想知道是否有任何公约或一般准则,以使用largeHeap设置,因为它可能是没有多大意义的话,也就是说,一个笔记应用程序使用largeHeap。一般来说,有什么应用程序是一个很好的候选人largeHeap设置?

感谢

解决方案
  

一般来说,哪些应用程序是一个很好的候选人largeHeap设置?

问鼎,你能证明的用户的你为什么要强迫所有其他应用程序的内存不足,给你的堆空间超大的金额。

就个人而言,我不认为一个图片库的应用程序的参赛资格。 AutoCAD中,视频编辑等,将有资格。

对于你的内存管理问题,请确保您在 BitmapOptions 使用 inBitmap 在API上运行时等级11+,所以在回收现有的缓冲区,而不是通过垃圾收集。特别是对于一个图片库,在那里你可能有很多相当一致的缩略图大小,回收利用现有的缓冲区将是一个巨大的好处。这可以帮助双方总内存消耗(例如,你是真正的内存不足)和内存碎片(也就是,你会得到一个的OutOfMemoryError 用大量的堆空间,但没有单人拦网足够大,你的配置,由于Android的frakkin非压缩垃圾收集器)。

您也可以考虑在寻找现有的图像缓存实现,比如一个毕加索有,看是否有一些提示,你可以学(或可能只是重复使用)。

I'm writing an image gallery app and I keep running into out of memory errors. I cache all my images but the problem occurs when I try switching between images really fast. I'm assuming the app is allocating memory faster than the GC has time to free them up (because the crash doesn't happen when I switch images slowly).

After banging my head against this problem for days, I finally decided to give largeHeap setting in the manifest file a try. After this setting, my app no longer crashes no matter how fast I switch between images.

Now, I want to know if there is any convention or general guideline to using largeHeap setting because it probably wouldn't make much sense if, say, a note taking app used largeHeap. Generally speaking, what apps are a good candidate for largeHeap setting?

Thanks

解决方案

Generally speaking, what apps are a good candidate for largeHeap setting?

Ones where you can justify to the user why you're forcing all their other apps out of memory, to give you an outsized amount of heap space.

Personally, I would not consider "an image gallery app" to qualify. AutoCAD, video editors, and the like would qualify.

With respect to your memory management issues, make sure that you are using inBitmap on BitmapOptions when running on API Level 11+, so you recycle existing buffers rather than go through garbage collection. Particularly for an image gallery, where you probably have a lot of fairly consistent thumbnail sizes, recycling existing buffers will be a huge benefit. This can help both overall memory consumption (i.e., you are truly out of memory) and memory fragmentation (i.e., you get an OutOfMemoryError with plenty of heap space, but no single block big enough for your allocation, due to Android's frakkin' non-compacting garbage collector).

You might also consider looking at existing image cache implementations, such as the one that Picasso has, to see if there are some tips you could learn (or possibly just reuse).

这篇关于机器人:largeHeap ="真"公约?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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