Forcing deallocation of large cache object in Java

后端 未结 7 987
醉梦人生
醉梦人生 2021-02-04 09:36

I use a large (millions) entries hashmap to cache values needed by an algorithm, the key is a combination of two objects as a long. Since it grows continuously (because keys in

7条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 10:24

    Clear the hashmap:

    hashmap.clear();
    

    Then force a garbage collector run:

    Runtime.getRuntime().gc();
    

    This is the Javadoc page for Runtime.gc().

提交回复
热议问题