Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Re: Not closing connections and statements Date: Sat, 13 Aug 2016 17:34:37 +0200 Organization: Decebal Computing Lines: 42 Message-ID: <87lh00k7hu.fsf@Equus.decebal.nl> References: <87shuakxjq.fsf@Equus.decebal.nl> <877fbkspps.fsf@mid.deneb.enyo.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="12baf5125b19322b899c79c2e3878015"; logging-data="10934"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19V3U3urP8RzQzaguQXnizVb3diWrjzoQs=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ Cancel-Lock: sha1:TTE67m1O7Ro8ukORv5epLlGYru0= sha1:WiP/Q/2vapdyog7j8Rmnb5gb7bQ= Xref: csiph.com comp.lang.java.programmer:35307 On Saturday 13 Aug 2016 16:33 CEST, Florian Weimer wrote: > * Cecil Westerhof: > >> At the moment I am writing a general function to log memory usage >> to a SQLite database to be used by different applications. How bad >> would it be if a program would exit without cleanly closing the >> connection and statement? > > Is the application long-running? How many statement objects do you > expect to leak this way? I am still no master in defining problems. :'-( It could be short running, but I expect it could also run for weeks. There is just one connection object and one statement object. No leaking is happening here. Normally I have an init and a deinit function. In the init function I create them and in the deinit function I close them. But I now wrote a function to log the memory usage. It is used by calling during the initialisation of you program: freeMemoryThread(this.getClass().getSimpleName()); Every statement, prepared statement and resultset is consumed immediately. That and the reason the updating is done as long as the program is running was the reason for my question. I rewrote the code a little so that all statement, preparedstatement and resultset are closed after being used. So that leaves only the connection. This is needed as long as the program is running and is in its own tread. As it looks like there is no real problem that it is not closed immediately before the program closes, I am accepting the situation as it is for now. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof