Smart pointers instead of GC?

Jonathan M Davis jmdavisProg at gmx.com
Tue Dec 25 11:23:05 PST 2012


On Tuesday, December 25, 2012 16:33:27 Leandro Lucarella wrote:
> On Tuesday, 25 December 2012 at 14:48:48 UTC, Sven Over wrote:
> >> Phobos does rely on the GC to some extent. Most algorithms and
> >> ranges do not though.
> > 
> > Running (library) code that was written with GC in mind and
> > turning GC off doesn't sound ideal.
> 
> It isn't if you care about memory leaks. And also bare in mind
> that some language constructs also relies on the GC, like some
> dynamic arrays operations (concatenation and appending for
> example). Right now is pretty hard to write D code that doesn't
> really use the GC at all.

There's also often no reason not to have the GC on and use it for certain stuff 
but use ref-counted objects as your main type of memory-management. Then, you 
avoid whatever issues the GC has in most cases but don't have to worry about 
what it takes to be able to not use it at all. For instance, arrays would 
probably be GC-allocated in general, since then you can use slices and 
whatnot, but maybe all of your user-defined objects on the heap could be 
malloced and freed with reference counts (though that sort of thing should be 
much easier once we have custom allocators - it's a bit more of a pain right 
now than it should be).

- Jonathan M Davis


More information about the Digitalmars-d mailing list