Object creation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anane
    New Member
    • Dec 2007
    • 9

    Object creation

    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?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Anane
    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?
    In Java all objects are dynamic, i.e. you always have to 'new' them and they
    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

    Comment

    • jashland
      New Member
      • Dec 2007
      • 2

      #3
      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!

      -Jeff

      Comment

      Working...