SoftReference gets garbage collected too early

前端 未结 5 1781
温柔的废话
温柔的废话 2020-12-08 17:17

I\'m on my way with implementing a caching mechanism for my Android application.

I use SoftReference, like many examples I\'ve found. The problem is, w

5条回答
  •  悲&欢浪女
    2020-12-08 18:13

    Gamlor's answer is correct in your situtation. However, for additional information, see the GC FAQ, question 32.

    The Java HotSpot Server VM uses the maximum possible heap size (as set by the -Xmx option) to calculate free space remaining.

    The Java HotSpot Client VM uses the current heap size to calculate the free space.

    This means that the general tendency is for the Server VM to grow the heap rather than flush soft references, and -Xmx therefore has a significant effect on when soft references are garbage collected.

提交回复
热议问题