The "no gc" crowd

Michel Fortin michel.fortin at michelf.ca
Wed Oct 9 10:13:51 PDT 2013


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.

D exceptions are classes and are heap-allocated. So if everything 
becomes reference-counted, exceptions would be reference-counted too. 
The exception handler would be the one decrementing the reference count 
once it has done with the exception (all this under the hood, managed 
by the compiler).

Alternatively an exception handler could return the exception to the 
parent function (as a return value), store the exception elsewhere, or 
throw it again, in which case the decrement operation would be balanced 
by an increment, and both increment and decrement should be elided by 
the compiler as they're cancelling each other.

I fail to see an issue.

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca



More information about the Digitalmars-d mailing list