garbage collection & use for delete
Brad Roberts
braddr at puremagic.com
Sun Mar 5 14:48:36 PST 2006
On Sun, 5 Mar 2006, akcom wrote:
> As I currently understand it, "deleting" an object simply marks it as ready
> for deletion when the garbage collector makes its period sweeps. After
> skimming through the phobos std source, I saw very VERY little use of the
> delete keyword, especially in regards to classes. My question is, how does
> the gc know when those classes are no longer being referenced? Also, are the
> explicit delete's I'm using on .dup'ed strings, classes, etc useless?
I'm fairly sure your understanding is wrong. You don't have to explicitly
delete objects and they will be cleaned up at some point by the garbage
collector (though that's not guaranteed in the face of things like the
program exiting). However, if you explicitly delete something, it's
destructor is called right then and there and the memory becomes available
for reuse immediately.
The docs on this are incomplete, imho, so I'll file a bug asking that they
be elaborated upon:
http://www.digitalmars.com/d/expression.html#DeleteExpression
Later,
Brad
More information about the Digitalmars-d-learn
mailing list