Advice wanted on garbage collection of sockets for c++ programmer using D

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 27 12:19:03 PDT 2017


On 6/27/17 2:04 PM, Moritz Maxeiner wrote:
> On Tuesday, 27 June 2017 at 15:24:00 UTC, Steven Schveighoffer wrote:
>> On 6/27/17 9:25 AM, Guillaume Piolat wrote:
>>> On Tuesday, 27 June 2017 at 13:11:10 UTC, Steven Schveighoffer wrote:
>>>> But I would use a close method, and not destroy(obj). The reason is 
>>>> because often times, you have wrapper types around your socket type, 
>>>> and just one extra level of indirection means the destructor cannot 
>>>> be used to clean up the socket (you are not allowed to access 
>>>> GC-allocated resources in a destructor).
>>>
>>> All destructor restrictions do not apply when it's not called by the GC.
>>>
>>> There really are two categories of destructors: called by the GC and 
>>> called deterministically. Their usage should not overlap.
>>
>> Yes, Tango solved this by having a separate "finalize()" method. I 
>> wish we had something like this.
> 
> Well, technically speaking the `~this` for D classes *is* a finalizer 
> that you may optionally manually call (e.g. via destroy).
> It would be nice, though, to change class `~this` into a destructor and 
> move the finalization into an extra method like `finalize`. Write a DIP?

I don't have enough motivation to do this. But if we do anything, we 
should look at what Tango has done. It may not work exactly for druntime 
because of existing code, but it obviously didn't need compiler changes 
to work.

-Steve


More information about the Digitalmars-d-learn mailing list