Destructor called while object is still alive
frame
frame86 at live.com
Fri Oct 23 20:27:37 UTC 2020
On Friday, 23 October 2020 at 19:39:52 UTC, Steven Schveighoffer
wrote:
> On 10/23/20 3:23 PM, frame wrote:
>> On Friday, 23 October 2020 at 17:47:34 UTC, Steven
>> Schveighoffer wrote:
>>> On 10/23/20 12:48 PM, Ola Fosheim Grøstad wrote:
>>>> On Friday, 23 October 2020 at 16:30:52 UTC, Steven
>>>> Schveighoffer wrote:
>
>
> 1. You generate a GC block (i.e. new class)
> 2. You store it as part of an initializer for a stack local
> 3. You never use it in the stack frame
> 4. But you also in that same initialization put it into a
> location that is not scanned by the GC (e.g. C-malloc'd data)
>
> If you aren't doing all 4 of these things, then you don't have
> to worry.
>
>> Actually I do use the pointer in real code, (just one method
>> call before a loop but still used).
>>
>
> So it shouldn't be collected then, even with optimizations.
>
> -Steve
But I doesn't do 3. and it's collected :(
There is no special release optimization, I just call it via rdmd
defaults.
Even if I do not run into memory problems, calling the destructor
on a live object is an unepxected side effect which makes the
dtor concept useless for me. It closes the remote connection the
object hold (please don't ask about the meaning, it just the way
it has to work) and this must not happen while the program is
still running.
More information about the Digitalmars-d
mailing list