Android: how to increase heap size at runtime?

前端 未结 5 1997
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 10:41

I have an image cache in my application which is implemented using SoftReferences. Dalvik starts applications with relatively small heap, and then increases it in case of de

5条回答
  •  执念已碎
    2020-12-09 10:48

    If the cache is ususally small as you say, you can decide a valid footprint of your app by yourself and maintain your own cache without SoftReferences.

    For example by a simple total byte counter: Just add or move any element used to the top of a list, add its size to the counter if it is new. Delete from the bottom if the total bytes exceed your rule-of-thumb limit, thereby decreasing your counter. Maybe the LinkedHashMap class is useful for that: It can be used as a cache like a HashMap, but it has an order too like a list.

提交回复
热议问题