문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top