>I have a persistence class with one dababase connection and no other member
>objects that need management. For reasons that are not necessary to go
[quoted text clipped - 6 lines]
> - The database connection won't close quite as quickly, and will be closed
> from a separate thread, but so what? It does close...
First, you should implement IDisposable. Whatever reasons you have that you
don't want to go into, you should get over them and implement IDisposable.
Second, don't use a Finalizer. The database connection has a finalizer
already.
Third, your question really is: "Is is alright for my application to leak a
few database connections?" The answer is yes, so long as you only leak one
connection, you should be fine, although it's still very bad design. But if
the usage or design of your app changes, and you start leaking more database
connections, your application will eventually and unpredictably fail.
David
Ben Voigt - 07 Dec 2006 21:03 GMT
>>I have a persistence class with one dababase connection and no other
>>member objects that need management. For reasons that are not necessary
[quoted text clipped - 11 lines]
> you don't want to go into, you should get over them and implement
> IDisposable.
I agree. Even if you decide not to call Dispose on your object, implement
IDisposable to give yourself the flexibility later.
> Second, don't use a Finalizer. The database connection has a finalizer
> already.
The reason is that if your finalizer calls the database's Dispose, you will
cause the database to be resurrected and its memory won't be freed until the
next GC pass. Even worse, the database could have been finalized already,
and calling any method (even Dispose) on an object after its finalizer has
run is very bad.
> Third, your question really is: "Is is alright for my application to leak
> a few database connections?" The answer is yes, so long as you only leak
[quoted text clipped - 4 lines]
>
> David
Brad Wood - 07 Dec 2006 21:46 GMT
> Even worse, the database could have been finalized already, and calling
> any method (even Dispose) on an object after its finalizer has run is very
> bad.
Thx. This is the important reason I was missing.