GC: memory collected but destructors not called
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Wed Nov 12 17:07:41 PST 2014
On 11/12/14 3:00 PM, Uranuz wrote:
> If we will have something like *scoped destructor* (that will be
> executed at scope exit) could it help to release some resources? I worry
> about this problem too because even using class to hold resource I
> expirience some *delays* in relesing them. For example I have database
> connection opened. And I want to close it when I finished my job.
> Relying on GC I sometimes experiece problems like *too many DB
> connections*, because GC frees it not enough quickly.
GC I would use as a last resort.
Let's say you leak the object, forget to dispose it. Do you want it to
leak the DB resource too?
Basically, you want a close() or dispose() method on your object, then
you can let the GC clean the memory, and synchronously close the DB
connection.
-Steve
More information about the Digitalmars-d
mailing list