Manual memory management in D2

Vladimir Panteleev vladimir at thecybershadow.net
Tue Jul 13 14:04:53 PDT 2010


On Tue, 13 Jul 2010 22:42:05 +0300, bearophile <bearophileHUGS at lycos.com>  
wrote:

> So in SafeD the delete operation can be replaced by something safer, a  
> way to tell the GC to deallocate just a specific object, walking the  
> graph and setting to null all the inbound pointers (this is a slower  
> operation).

I'd just like to point out that, without some careful considerations, this  
would allow any code to modify memory belonging to completely unrelated  
code it knows nothing about. Without careful planning it could cause the  
program to crash due to null pointer dereferences in completely unrelated  
areas, leaving you scratching your head why is that pointer null in the  
first place.

I think that a better idea is "safe deletion": make a precise GC examine  
the entire graph and make sure that the calling code has the only  
reference to the object before deleting it.

(This isn't practical anyway, because it'd probably be too slow to be  
useful for most cases, and doesn't apply to current D implementations.)

-- 
Best regards,
  Vladimir                            mailto:vladimir at thecybershadow.net


More information about the Digitalmars-d mailing list