Subject Memory Leak in client-java - FIXED!
Author Lars George
Hi,

We discovered that there were quite a few memory leaks in the last
firebirdsql.jar that is available for download on the project website. Any
isc_stmt_handle object was not garbage collected. But since then we got the
latest version of the CVS repository and that leak seemed to be fixed. Could
anyone confirm this?

But we still found another one. Whenever you execute a query and ask for the
ResultSet it will not release the isc_tr_handle. See the following heap dump
after 6000 execute statements:

SITES BEGIN (ordered by live bytes) Thu Oct 24 14:48:32 2002
percent live alloc'ed stack class
rank self accum bytes objs bytes objs trace name
1 14.70% 14.70% 393048 16377 393048 16377 2419 java.lang.String
2 12.57% 27.27% 336056 6001 336112 6002 2048 java.lang.Object
3 12.57% 39.84% 336000 6000 336000 6000 2389 java.lang.Object
5 5.39% 50.74% 144000 6000 144000 6000 2390 java.util.HashMap$Entry
6 5.39% 56.12% 144000 6000 144000 6000 2388 java.util.ArrayList
7 5.39% 61.51% 144000 6000 144000 6000 2400 java.util.ArrayList
8 5.39% 66.90% 144000 6000 144000 6000 2399
org.firebirdsql.jgds.isc_tr_handle_impl
9 2.92% 69.82% 78184 762 79528 789 1 [C
10 2.52% 72.35% 67496 699 67496 699 2178 [C
11 1.84% 74.19% 49160 1 98288 10 2409 java.util.HashMap$Entry

You can see the 6000 isc_tr_handle_impl objects being retained. I debugged
the source code and found the problem. It is located in the
org.firebirdsql.jca.FBManagedConnectionFactory.java class. It stores a
reference to the transaction when a statement returns a ResultSet in
registerStatementWithTransaction(). The list used is static. The leak is
that this reference is never removed. Below is the fix - basically a single
line of code - that removes the transaction reference when the resultsets
are discarded:

private void forgetResultSets(isc_tr_handle tr) {
//shouldn't need synchronization, only called by rollback and
commit- then we're done
//transaction/thread should also help.
ArrayList stmts = (ArrayList)TransactionStatementMap.get(tr);
if (stmts != null) {
Iterator i = stmts.iterator();
while (i.hasNext()) {
((FBStatement)i.next()).forgetResultSet();
}
stmts.clear();
}
// lars 2002-10-24: Fix memory leak - release transaction from
static list
TransactionStatementMap.remove(tr);
}

Since it is private and used only in two spots (commit and rollback) it
seems the best fit to implement the fix. Could someone do a code review on
this and check the fix into CVS please?

Thanks,
Lars

----- Original Message -----
From: "Carsten Schäfer" <ca_schaefer@...>
To: <Firebird-Java@yahoogroups.com>
Sent: Thursday, October 24, 2002 6:56 PM
Subject: Re: [Firebird-Java] Re: Periodical Server-Crashes


Maybe i can write a test class to show my connection management.
You can downlad JSL from the site i have posted, but i use jsl at all of my
costumers (about 20) without problems.

Thank you for posting my message to the db newsgroup, but i think there is a
mistake.
I think the original problem with the nonpaged memory is solved now. (by
David Jencks)
(I can't say exactly because now my app crashes to often)
The original problem was not that the JVM crashes, it was that because of
the memory leak windows doesn't allow clients anymore to connect to the
windows server (network problem).
(My app did not crash)
The original problem was with a Jaybird version RC1 (or selfcompiled 1 week
before RC1).
The new problem (JVM crashes) happens with new version of Jaybird David
Jencks sent me 2 weeks ago.
Maybe someone can sent me an actual windows compiled version (JDK1.3).
I can sent you the dr-watson.log file that logs the crashes (i don't
understand what it says).

gruß
Carsten

----- Original Message -----
From: "Roman Rokytskyy" <rrokytskyy@...>
To: <Firebird-Java@yahoogroups.com>
Sent: Thursday, October 24, 2002 10:23 AM
Subject: [Firebird-Java] Re: Periodical Server-Crashes


> Hi,
>
> > What do you mean with testing code ?
> > My app has about 1000 classes, it's client-server via rmi, only
> > server doing db connecting.
>
> Ok, probably not the best idea. I wanted to start the code that does
> JDBC connection management on my machine and see if I get similar
> problems.
>
> I posted your original message to IB-Support group, maybe we get some
> replies there. In meantime, can you check what sockets are opened on
> that server? Can you also check that your application does not try to
> open non-existing port all the time?
>
> > What is JSL ?
>
> Something that is promoted on the site you referenced in one of your
> posts (Java Service Launcher). I thought it is somehow connected to
> your problem.
>
> Best regards,
> Roman Rokytskyy
>
>
>
> To unsubscribe from this group, send an email to:
> Firebird-Java-unsubscribe@yahoogroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


To unsubscribe from this group, send an email to:
Firebird-Java-unsubscribe@yahoogroups.com



Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/