The "no gc" crowd

Johannes Pfau nospam at example.com
Wed Oct 9 10:36:01 PDT 2013


Am Wed, 9 Oct 2013 13:13:51 -0400
schrieb Michel Fortin <michel.fortin at michelf.ca>:

> On 2013-10-09 16:51:03 +0000, Manu <turkeyman at gmail.com> said:
> 
> > On 10 October 2013 01:40, Johannes Pfau <nospam at example.com> wrote:
> > 
> >> But if someone really wants to strip the GC _completely_ there's a
> >> huge issue with memory management of Exceptions.
> > 
> > Exceptions have a pretty well defined lifetime... can't they be
> > manually cleaned up by the exception handler after the catching
> > scope exits?
> 
> Exceptions don't need a well-defined lifetime for things to work.

What I meant was using exceptions without the GC requires huge changes
(like switching all exceptions to use reference counting) or at least
using the same type of allocation for all exceptions. If you have
'malloced' and GC owned exceptions it can be hard to know if an
Exception needs to be freed:

try
{
    codeWithMallocException();
    codeWithGCException();
}
catch(Exception e)
{
    //Am I supposed to free this exception now?
}

Now think of exception chaining... I think this can easily lead to
memory leaks or other latent issues.

So avoiding parts of phobos which allocate right now is relatively easy.
Switching all code to use 'malloced' Exceptions is much more work.

> D exceptions are classes and are heap-allocated. So if everything 
> becomes reference-counted, exceptions would be reference-counted too. 
> [...]
> I fail to see an issue.
> 

I meant it's complicated right now, without compiler / runtime / phobos
changes. You can avoid parts of phobos as a user but getting rid of
GC allocated exceptions is more difficult. Of course if you can change
all exceptions to use reference counting that works well but that's a
rather big change.


More information about the Digitalmars-d mailing list