Two Laptop Bag
The moose likes Java in General and the fly likes garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "garbage collection" Watch "garbage collection" New topic

garbage collection

william kane
Ranch Hand

Joined: Nov 21, 2000
Posts: 260
What do Runtime.getRuntime().totalMemory() and
Runtime.getRuntime().freeMemory() return?
When i create new objects i expect the freeMemory to reduce and totalMemory to increase, but, the the totalMemory is remaining constant.
is my expectaion right?

Help me!Help you!!!
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
freeMemory + usedMemory = totalMemory
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

Steve is right, totalMemory is a constant. It's configurable at initialization time, and that's it. "used memory" is the value you expect to increase with object creation.

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Nope. Steve's equation is right - but total memory is not a constant.

Total memory refers to the total heap size currently allocated to the JVM. This can and does change over time , if the application attempts to use more memory, and the JVM has not yet used its allowed maximum. That's why there's a difference between the -ms and -mx options when invoking the JVM.
[ February 27, 2002: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: garbage collection
It's not a secret anymore!