Re: Memory leak ?

Поиск
Список
Период
Сортировка
От Guillaume Cottenceau
Тема Re: Memory leak ?
Дата
Msg-id 8739luy21c.fsf@mnc.ch
обсуждение исходный текст
Ответ на Re: Memory leak ?  (Lew <noone@lewscanon.com>)
Список pgsql-jdbc
Lew <noone 'at' lewscanon.com> writes:

> Guillaume Cottenceau wrote:
>> Pierre Le Mouëllic writes:
>>
>>> With this code :
>>>
>>> public class TestJDBC {
>>
>> [...]
>>
>>>              try {
>>>                  sQLStatement.setInt(1, 2602);
>>>                  rs = sQLStatement.executeQuery();
>>>                  sQLStatement.setInt(1, 2604);
>>>                  rs = sQLStatement.executeQuery();
>>>                  sQLStatement.setInt(1, 2605);
>>>                  rs = sQLStatement.executeQuery();
>>>              } catch (SQLException e) {
>>>              }
>>>              finally{
>>>
>>>                  try {
>>>                      if(rs!=null)
>>>                          rs.close();
>>
>> e.g. you explicitely close only the last resultset of the three
>> you produced (assuming no exception)
>
> So?  Why is that an issue?

Did I say it is an issue?

> <http://download.oracle.com/javase/6/docs/api/java/sql/ResultSet.html>
>
> "A ResultSet object is automatically closed when the Statement object
> that generated it is closed, re-executed, or used to retrieve the next
> result from a sequence of multiple results."

Yes, it is not an issue.

>>> In eclipse Helios profiler, Jdbc3ResultSet live instances increase (and never
>>> decrease). Same thing with
>>
>> Garbage collection is not predictable, closing resultsets [sic] (and
>> statements) is strongly adviced if you want to release JDBC
>> resources in a timely manner.
>
> No.
>
> Closing a 'ResultSet' is actually not advised.  Well, sometimes, but
> generally you should close its 'Statement'.

I'm no expert on that, so it's one more reason why I'm not going
to lose too much time on that by answering once to illustrate my
claims, and then let it go if that creates more fuss. I hope I
can learn from this actually so that's not a call from you to not
answer that message if you see wrong claims.

I'm stating closing (of resultsets and statements) is adviced
from memories of messages on this list and other lists, and this
seems to be supported by the documentation over there:

http://download.oracle.com/javase/6/docs/api/java/sql/ResultSet.html#close()

In particular:

"Releases this ResultSet object's database and JDBC resources
immediately instead of waiting for this to happen when it is
automatically closed."

I don't see why it would be "actually not adviced" as you say. So
there is an API, whose name is "close" which is similar to other
names used in java API to immediately release external resources
instead of waiting for the GC to do so, and whose documentation
says the same thing, but it would be adviced to not use it? Seems
odd.

> In the OP's case he did the right thing by closing just the
> last 'ResultSet', since he wanted his 'Statement' to stay
> alive.

Closing the two first resultsets would not allow this statement
to stay alive? That doesn't seem supported by the documentation
of the close method.

--
Guillaume Cottenceau

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: Recommended resource type and settings for J2EE/Glassfish connection pool
Следующее
От: Achilleas Mantzios
Дата:
Сообщение: Re: time and timetz : Do I miss something?