• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Memory problem with objects of JDBC

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic