GC: memory collected but destructors not called

via Digitalmars-d digitalmars-d at puremagic.com
Wed Nov 12 12:45:59 PST 2014


On Wednesday, 12 November 2014 at 20:00:31 UTC, Uranuz wrote:
> If we will have something like *scoped destructor* (that will 
> be executed at scope exit) could it help to release some 
> resources?

Don't know what you mean here. Isn't that just a normal 
destructor?

> 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.

I'd say database connections and file descriptors simply 
shouldn't be managed by the GC. It is good at managing memory, 
but not for other things. It's better to have a connection pool, 
and from that pool take a reference to the DB connection, use it 
as long as you need it, and then give it back. This can be 
implemented nicely with scope(exit).


More information about the Digitalmars-d mailing list