When we use NEW word to create object of a class, it always creates object on HEAP memory. How can one create object on stack? If one creates object inside a function, then also object will be created in HEAP. Only object reference will be in stack. When function ends, object reference is destroyed, eventually object will be destroyed by GC. Am I correct with this concept?
Object creation
Collapse
X
-
Originally posted by AnaneWhen we use NEW word to create object of a class, it always creates object on HEAP memory. How can one create object on stack? If one creates object inside a function, then also object will be created in HEAP. Only object reference will be in stack. When function ends, object reference is destroyed, eventually object will be destroyed by GC. Am I correct with this concept?
are always created on a heap (not a C/C++ like heap); you can't create them
on the execution stack. And yep, you are correct.
kind regards,
Jos -
There was a really good talk last year about eden space and such at JavaOne. It answered some questions about this topic I've always had. Lemme see if I can drudge up the link..
I think this is it: http://developers.sun.com/learning/j...r=2007&track=5
Hope it helps a bit!
-JeffComment
Comment