GC Destruction Order

Kagamin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 20 08:09:28 PDT 2015


On Wednesday, 20 May 2015 at 13:54:29 UTC, bitwise wrote:
> Yes, but D claims to support manual memory management. It seems 
> to get second class treatment though.

It's WIP. There were thoughts to run finalizers on the thread 
where the object was allocated (I doubt it's a good idea, 
though). Anyway, if you're doing manual memory management, how GC 
popped up? If you have your manual memory managed with GC, it 
means you have a memory leak: manually managed memory shouldn't 
become garbage without being freed. I suppose it will be a long 
way before D rediscovers .net practices.

> I'm pretty sure I can PInvoke malloc in C# too ;)

I use Marshal.AllocHGlobal.

>>> Basically, I can't design a struct and be sure the destructor 
>>> will be called on the same thread as where it went out of 
>>> scope.
>>
>> If your resource finalization code has some specific threading 
>> requirements, you implement those yourself in a way your code 
>> requires it. Or instead freeing resources normally in due time.
>
>  AFAIK D does not provide any built in functionality like 
> Objective-C's 'runOnMainThread', which makes this a painful 
> option.

You asked for destructor being called on the thread where it went 
out of scope, which is not necessarily the main thread.


More information about the Digitalmars-d-learn mailing list