Best way to manage non-memory resources in current D, ex: database handles.

Kagamin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 9 08:39:14 PST 2017


Unique is probably not good for database connection: you then 
can't have connection in two variables, also if it holds a 
reference to GC-allocated memory, it can't be put to GC-allocated 
memory, since when that GC-allocated memory is collected, Unique 
will try to destroy its possibly already freed object resulting 
in use after free. RefCounted is ok, it has calls to GC in order 
to be scanned for GC references, though destructors during 
collection are called in a different thread, so the counter can 
be decremented incorrectly. Phobos tends to have specialized 
types like File and RcString, but they have the same problem with 
reference counting during collections.


More information about the Digitalmars-d-learn mailing list