Garbage consists of objects that can't be referenced by anyone -- there are no static, instance, or local variables that references them either directly or indirectly.
Assign null to variables that you are no longer using. This will, if there are no other references, allow this memory to be recycled (garbage collected). Because local variables are deallocated when a method returns, they are less of a problem. Variables with the longest lifetime are static variables, you should be careful to assign null to any that are no longer used, especially if they reference large data structures.
No comments:
Post a Comment