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?
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 ]