How to make the java system release Soft References?

后端 未结 5 1697
慢半拍i
慢半拍i 2020-12-05 11:06

I\'m going to use a SoftReference-based cache (a pretty simple thing by itself). However, I\'ve came across a problem when writing a test for it.

The objective of th

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 11:31

    You could explicitly set the soft reference to null in your test, and as such simulate that the soft reference has been released.

    This avoids any complicated test setup that is memory and garbage collection dependend.

提交回复
热议问题