Help me settle a dispute with a coworker: Does setting a variable or collection to null in Java aid in garbage collection and reducing memory usage? If I have a long running
Setting an object reference to null only makes it eligible for garbage collection. It does not necessarily free up the memory,which depends on when the garbage collector runs(which depends on JVM). When the garbage collector runs,it frees up the heap by deleting only the objects which are eligible for garbage collection.