Originally posted by Chandra Bairi:
stmt=null;
con=null;
i guess including the above statements will help the GC to collect the objects when it is run. if we dont have the above two statements then the memory occupied by the above two objects may or may not be released.
It depends on the scope of stmt and con. If they are declared in a method, they will go out of scope when the method ends and explicity setting them to null is not necessary for them to be GC'd. If they are instance variables, they will last as long as the instance that declares them exists or until the references are nulled. If they are static class variables they will be around for the life of the program or until their references are set to null.