This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hello all, I have created a connection object saying Connection con = DriverManager.getConnection() and then executed a query by creating a statement object. Statement stmt = con.createStatement(); i have also closed the connection and the stmt object saying stmt.close(); con.close();
but i would like to know will there be any memory problem or will the objects con and stmt occupy space in memory if we dont say the following statements after stmt.close() and con.close() 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. can anyone help me in this regard thanks shekar.
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.