dogbane
dogbane

Reputation: 274522

In-memory database close()

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).

Upvotes: 1

Views: 364

Answers (2)

Piskvor left the building
Piskvor left the building

Reputation: 92752

  • 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".

Upvotes: 0

Bozho
Bozho

Reputation: 597016

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.

Upvotes: 2

Related Questions