Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38747
| X-Received | by 2002:ac8:1997:: with SMTP id u23mr4689734qtj.11.1551363548135; Thu, 28 Feb 2019 06:19:08 -0800 (PST) |
|---|---|
| X-Received | by 2002:a25:2591:: with SMTP id l139mr6815859ybl.481.1551363547958; Thu, 28 Feb 2019 06:19:07 -0800 (PST) |
| Path | csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!m21no4547558qta.0!news-out.google.com!o7ni1760qta.1!nntp.google.com!m21no4547554qta.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.java.programmer |
| Date | Thu, 28 Feb 2019 06:19:07 -0800 (PST) |
| In-Reply-To | <slrnq7fkg8.cfl.avl@logic.at> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=50.78.95.177; posting-account=2czF5goAAAD4GBMPIGV4KcD2K4PhoB_H |
| NNTP-Posting-Host | 50.78.95.177 |
| References | <slrnq7dcgo.cfl.avl@logic.at> <709a1f3b-fc99-4bd0-a8b8-866092bb7ae9@googlegroups.com> <slrnq7dnnu.cfl.avl@logic.at> <8e1597a2-5c18-4fd1-83a4-7667e4d11e77@googlegroups.com> <slrnq7fkg8.cfl.avl@logic.at> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <23a8128b-5c54-45ba-bfd0-2f7dda078517@googlegroups.com> (permalink) |
| Subject | Re: it's Closeable, but I don't want to close() it yet. |
| From | Eric Douglas <e.d.programmer@gmail.com> |
| Injection-Date | Thu, 28 Feb 2019 14:19:08 +0000 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | quoted-printable |
| Lines | 39 |
| Xref | csiph.com comp.lang.java.programmer:38747 |
Show key headers only | View raw
On Thursday, February 28, 2019 at 7:20:35 AM UTC-5, Andreas Leitgeb wrote: > The Closeable interface does not provide any concept of opening. > Eclipse just sees a local variable of a Closeable type that > goes out of scope without .close() being called on it. Whether Eclipse cares depends on the scope. I had the "Potential Resource Leak" error set to ignore because it was flagging potential leaks which should not be leaks. For example I had 2 methods opening different kinds of InputStream, passing their streams into one common method to read them. The method reading the streams was guaranteed to close the stream for them using a try-finally block, but I didn't see a way to tell Eclipse that, so it complained about the methods which opened the streams. The only way to avoid that warning is to put the method that opens the stream in yet another try-finally block that attempts to close it again. I don't know if this logic makes sense, or if the method that only reads the streams should never close them, but it seems tedious. In another class where I really didn't want to close the resource, I opened it in the constructor. It didn't complain about that. If you want to create one java.sql.Connection to use for multiple queries, declare it outside of your method and there's no warning. It doesn't warn to close it if I open it in the method and it's declared outside (class level variable). Obviously it's a big deal if you open multiple instances of java.sql.Connection without closing them. I'm not sure the impact of the other classes. In order to execute a query, I open the Connection, then I open a java.sql.Statement, then I open a java.sql.ResultSet. Eclipse shows all 3 of these require their own close. What happens if you don't close the Statement, does it eat up excess memory? Does it keep all query results in memory indefinitely if you don't close the ResultSet? These classes are AutoCloseable, so you can do a try with resources to close them. Eclipse doesn't care if they're closed if you declare them as class level, and doesn't expect them to close if they're the return value, though I'm not sure about embedded values. Can you create multiple closeable objects and pass them out in an array or map? One way or the other, all closeable resources must get closed. If you have another method to guarantee they get closed outside of where they're declared, the simple answer is suppress the warning.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-27 15:51 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-27 08:48 -0800
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-27 19:03 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-27 11:09 -0800
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-28 12:20 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 06:19 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 06:52 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 08:24 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 08:34 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 09:00 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 11:12 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:26 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 11:33 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:37 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 11:41 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:48 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 12:51 -0800
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-01 08:47 +0000
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-01 09:31 +0000
Re: it's Closeable, but I don't want to close() it yet. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-03-03 02:01 +0100
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-04 09:38 +0000
Re: it's Closeable, but I don't want to close() it yet. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-03-04 12:26 +0100
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-05 14:34 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-03-05 07:34 -0800
Re: it's Closeable, but I don't want to close() it yet. Arne Vajhøj <arne@vajhoej.dk> - 2019-03-04 13:59 -0500
Re: it's Closeable, but I don't want to close() it yet. Marcel Mueller <news.5.maazl@spamgourmet.org> - 2019-02-28 08:30 +0100
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-02-28 19:10 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 11:34 -0800
Re: it's Closeable, but I don't want to close() it yet. Marcel Mueller <news.5.maazl@spamgourmet.org> - 2019-02-28 22:24 +0100
Re: it's Closeable, but I don't want to close() it yet. Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-02-28 23:25 +0100
Re: it's Closeable, but I don't want to close() it yet. Andreas Leitgeb <avl@logic.at> - 2019-03-01 09:43 +0000
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 12:11 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 13:49 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 13:52 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 13:59 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-02-28 16:17 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 12:26 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-02-28 13:44 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-03-01 07:40 -0800
Re: it's Closeable, but I don't want to close() it yet. bursejan@gmail.com - 2019-03-01 08:34 -0800
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-03-11 06:27 -0700
Re: it's Closeable, but I don't want to close() it yet. Eric Douglas <e.d.programmer@gmail.com> - 2019-03-11 07:24 -0700
csiph-web