Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning "null" to objects in every application after their use

  • Do you always assign null to an object after its scope has been reached?

  • Or do you rely on the JVM for garbage collection?

  • Do you do it for all sort of applications regardless of their length?

  • If so, is it always a good practice?

like image 808
Sajal Dutta Avatar asked Dec 04 '09 16:12

Sajal Dutta


2 Answers

It's not necessary to explicitly mark objects as null unless you have a very specific reason. Furthermore, I've never seen an application that marks all objects as null when they are no longer needed. The main benefit of garbage collection is the intrinsic memory management.

like image 112
Taylor Leese Avatar answered Sep 22 '22 12:09

Taylor Leese


  • no, don't do that, except for specific cases such as static fields or when you know a variable/field lives a lot longer than the code referencing it
  • yes, but with a working knowledge of your VM's limits (and how to cause blocks of memory to be held accidentally)
  • n/a
like image 34
Marc Gravell Avatar answered Sep 18 '22 12:09

Marc Gravell