*
The moose likes Beginning Java and the fly likes Object life cycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object life cycle" Watch "Object life cycle" New topic
Author

Object life cycle

Sindu Ram
Greenhorn

Joined: Aug 05, 2003
Posts: 6
Hi,
I was recently asked a question about an object life cycle in Java, especially with regard to what happens when we do an
A a = new A();
and what goes to the stack and what to the heap.
Any info would be welcome.
Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Local variables are kept on the stack, while objects are kept on the heap. If this line of code is in a method, then the variable a is on the stack and the A object is on the heap; if it's a line of code at the top level of a class, then a is inside some other object on the heap, and the A is also on the heap.


[Jess in Action][AskingGoodQuestions]
Sindu Ram
Greenhorn

Joined: Aug 05, 2003
Posts: 6
Thank you, Ernest..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object life cycle