Java – when to use runtime Maxmemory() and totalmemory() [copy]

See English answers > What are runtime getRuntime(). totalMemory() and freeMemory()? 6

What are the typical use cases of these two methods, that is, when it is inappropriate to use the corresponding other method?

Solution

Totalmemory () returns the amount of memory currently in use, and maxmemory () tells the JVM how much memory can be allocated

Note: it can be concluded that totalmemory() < = maxmemory(), you can also get 'how much memory is left' through maxmemory() - a use case of totalmemory() is to diagnose how much memory your program uses, and then you will use totalmemory() Note: both refer only to heap memory, not stack memory

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>