Will reassigning a reference variable to null before reassigning it to a new object releases the old memory which it used to hold or is it the work of Garbage Collector?
Dog obj = new Dog("d1");
if(obj!=null)
obj = null; // will this release the memory?
obj = new Dog("d2");
OR
Dog obj = new Dog("d1");
obj = new Dog("d2");