Skip to main content

How to get the used heap size?

3 replies [Last post]
blueshycool
Offline
Joined: 2008-03-23

When the CVM is running, I want to get the used heap size.Is there any functions I can call?
Or a value I can get?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
blueshycool
Offline
Joined: 2008-03-23

Thank you very much!
I see!

Best wishes!

mlam
Offline
Joined: 2006-10-13

Blueshycool,

From Java code, you can call Runtime.getRuntime().freeMemory() and Runtime.getRuntime().totalMemory(). The used heap size can be computed by subtracting free memory from total memory. Note that the value of total memory can change. It is automatically resizable y the VM depending on the needs of the system. The max value it can grow up to can be attained by calling Runtime.getRuntime().maxMemory().

Hence, when computing the used memory, you will always need to get both the free and total memory at that moment before computing the used value. Note that getting both the free and total memory values won't guarantee that you have 2 values which are consistent with each other (for reasons that are too complex to explain right now), but it will make it very likely that the 2 are consistent.

For the most part, this should probably be good enough for most people's (and presumable your) needs. If you have more specific needs regarding memory usage, then please let us know.

Regards,
Mark

Hinkmond Wong

Thanks, Mark! :-)

Hinkmond

phonemeadvanced@mobileandembedded.org wrote:
> Blueshycool,
>
> From Java code, you can call Runtime.getRuntime().freeMemory() and Runtime.getRuntime().totalMemory(). The used heap size can be computed by subtracting free memory from total memory. Note that the value of total memory can change. It is automatically resizable y the VM depending on the needs of the system. The max value it can grow up to can be attained by calling Runtime.getRuntime().maxMemory().
>
> Hence, when computing the used memory, you will always need to get both the free and total memory at that moment before computing the used value. Note that getting both the free and total memory values won't guarantee that you have 2 values which are consistent with each other (for reasons that are too complex to explain right now), but it will make it very likely that the 2 are consistent.
>
> For the most part, this should probably be good enough for most people's (and presumable your) needs. If you have more specific needs regarding memory usage, then please let us know.
>
> Regards,
> Mark
> [Message sent by forum member 'mlam' (mlam)]
>
> http://forums.java.net/jive/thread.jspa?messageID=266892
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: advanced-unsubscribe@phoneme.dev.java.net
> For additional commands, e-mail: advanced-help@phoneme.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: advanced-unsubscribe@phoneme.dev.java.net
For additional commands, e-mail: advanced-help@phoneme.dev.java.net