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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object memory" Watch "Object memory" New topic
Author

Object memory

Aaron Webb
Greenhorn

Joined: Aug 16, 2001
Posts: 17
If I do...
SomeObject obj = new SomeObject();
obj = new SomeObject();
...what happens in memory? Does the new object replace the first one?
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Aaron
What will happen is that the variable obj will refer to the newly created object of type SomeObject. The original object that it refered to will become eligible for garbage collection and at some point the GC will destroy it and reclaim the memory that it used.
The new object doesn't replace the other one in memory the location of the new one will replace the location of the original one in the varialbe obj.
Did that answer it for you?


Dave
 
 
subject: Object memory
 
Similar Threads
ArrayList, contains, objects
what is the use of interface which has no methods?
Question on Garbage Collection
Clarification on Sefl test - K&B book
a question about the toString()