Finding Memory Usage in Java

后端 未结 8 2427
野趣味
野趣味 2021-02-09 13:52

Following is the scenario i need to solve. I have struck with two solutions.

I need to maintain a cache of data fetched from database to be shown on a Swing GUI. Wheneve

8条回答
  •  一个人的身影
    2021-02-09 14:22

    I've only used the first method for similar task and it was OK.

    One thing you should note, for both methods, is to implement some kind of debouncing - i.e. once you recognize you've hit 70% of memory, wait for a minute (or any other time you find appropriate) - GC can run at that time and clean up lots of memory.

    If you implement a Runtime.freeMemory() graph in your system you'll see how the memory is constantly going up and down, up and down.

提交回复
热议问题