How to call destructor before free without dropping @nogc?

Ferhat Kurtulmuş aferust at gmail.com
Thu Aug 19 19:21:48 UTC 2021


On Thursday, 19 August 2021 at 15:38:19 UTC, evilrat wrote:
> On Thursday, 19 August 2021 at 15:12:03 UTC, Ferhat Kurtulmuş

> This is cool, but even in unit tests for malloc wrapper there 
> is only simple case with class without references to another 
> class and no dtor.

If you examine the entire library, there are various use cases of 
nogc classes. For instance, a derived class containing references 
to other class objects [1]. I am not using classes heavily with 
D. I just once happily used dplug's nogc facilities. When I saw 
this thread, I just wanted to share it here.

> Seems like the issue is that one have to add @nogc 
> constructor/destructor overloads for emplace/destroy, and the 
> author can't have @nogc dtor because of writeln (IIRC @nogc 
> using GC is allowed with `debug` anyway), and all class members 
> of another classes must recursively provide them as well.

I agree with you. D needs more nogc facilities for OOP. It would 
not be so hard to include those overloads. Probably, this would 
violate the strictly defended safety principles of D?

[1]: 
https://github.com/AuburnSounds/Dplug/blob/f67c14fd5ba44225d6669e87f942d641c8bf8ab8/window/dplug/window/cocoawindow.d


More information about the Digitalmars-d-learn mailing list