Allocation of memory
Hi All,
I'm really sorry i'm askin a naive question. when we create a new string object or for that matter any object by writing
String str =new String("Hi!");
who allocates memory for the object; the JVM or the underlying operating system. Also i would like to have some references for the JVM.
When the JVM starts up it reserves (but doesn't commit) a range of addresses to use as the Java Object heap. When you write new String("Hi!")
part of that reserved space is committed to represent the char[] for the "Hi!", and another part is committed for the String instance that holds a reference to the char[]. When there are no more references to the String, the JVM recovers the space for use as other instances.
There's a whitepaper on memory management in the HotSpot virtual machine at http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf