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.
The moose likes JDBC and the fly likes Memory problem with  objects of JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Memory problem with  objects of JDBC" Watch "Memory problem with  objects of JDBC" New topic
Author

Memory problem with objects of JDBC

Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
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.


Thanks,
Shekar
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8264

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Memory problem with objects of JDBC
 
Similar Threads
nee help how to compare objects......
Try/Catch/Return
Problems in Closing PreparedStatements using WS AS 3.5 Connection Pooling using Oracl
help regarding jdbc
Hi,I have a problem in database connection