C++ approach of Object Destruction
Java Approach of object destruction
Java's approach is automatic garbage collection. You can add a finalize method to any class. The finalize method will be called before the garbage collector sweeps away the object. In practice, do not rely on the finalize method for recycling any resources that are in short supply—you simply cannot know when this method will be called. So java follows non-deterministic approach.
Advantage of Garbage collection
See here for advantage of garbage collection.
Disadvantage of Garbage collection
See here for disadvantage of Garbage collection
Final note
Garbage collection has increased problem, rather than solving many. Due to limited memory, we can get out of memory error. But this problem or disadvantage, we have to live with java.
No comments:
Post a Comment