Subject Should (Could) FBStatements be held in WeakHashMap
Author Mark O'Donohue

In FBConnection active statements are held in a HashSet.

I was wondering if anyone had thought of changing this to a WeakHashMap?

It would mean that if one forgets to call the stmt.close() method that
they would get picked up by a System.gc() call.

Not that one would admit to using such poor coding style as to forget to
add the close() :-). But in case one did you would get a :

Exception in thread "main" java.lang.RuntimeException: Unable to close
BLOB input stream."

or similar message, which is not very clear.

From there it took a fair amount of fiddling, eventually arriving at
the (old) Heap Analysis Tool,

(I had to hack the code to get it to load profiles from jdk1.4.1) but
then when I realised I had well over 20,000 FBCallableStatment
instances, which then pointed to the correct source of the error.

The only link holding them in memory was the above HashMap. The
looking at the code, in FBConnection:

// This set contains all allocated but not closed statements
// It is used to close them before the connection is closed

private java.util.HashSet activeStatements = new java.util.HashSet();

So closing the connection would work, but it would be nice to have a
safty net, particularly since the error message is not so clear, which
leads me to wonder if a WeakHashMap could be used here instead.