android:largeHeap=“true” convention?

后端 未结 2 1464
Happy的楠姐
Happy的楠姐 2020-12-09 10:06

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 real

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 10:37

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

提交回复
热议问题