views:

44

answers:

2

In an in-memory database, is it necessary to close ResultSets, Statements and Connections?

My Java program uses HSQLDB to create a "memory table" and populate it with data, which it later queries. There is no persistence. Everything is done in memory. The program is single-threaded and only has one database connection (i.e. no database connection pooling).

+2  A: 

It's always best to close your jdbc objects - otherwise you risk memory leaks.

Read (at least) items 6 and 7 from Effective Java, Chapter 2 - they are more or less related.

Bozho
A: 
  • connections: definitely (as the DB may have a connection limit; in case you'd put it on a different server, there's also network overhead)
  • other objects: database may not care, but your JVM keeps them in memory too (and won't GC them).

Plus, it's good practice to clean up after yourself, so you have a better view of "what I'm working with now".

Piskvor