Posts Tagged ‘Java’
Garbage Collection in Java and Design Patterns
Managing object deletion in Java is made automatically by Garbage Collector. Having this in mind it is crucial to know how to implement some patterns (like the Observer) which has a communication line (realized with storing refs) between objects.
Instead of the default object reference I offer you to use java.lang.ref.*
It is important to use not default object references in order instruct Garbage Collector to delete the object when up to him are only weak object references (which refs are supposed to keep the object in some pattern but not to keep it away of Garbage Collector).