InvalidMemoryOperationError@(0)

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 17 19:48:38 PST 2014


On 11/17/14 6:38 PM, Vladimir Panteleev wrote:
> On Monday, 17 November 2014 at 22:40:36 UTC, Steven Schveighoffer wrote:
>> On 11/17/14 5:19 PM, Vladimir Panteleev wrote:
>>> On Monday, 17 November 2014 at 16:40:18 UTC, ketmar via
>>> Digitalmars-d-learn wrote:
>>>> On Mon, 17 Nov 2014 15:41:25 +0000
>>>> Andre via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
>>>> wrote:
>>>>
>>>>>    ~this()
>>>>>    {
>>>>>        foreach(cp; this._columns)
>>>>>        {
>>>>>        }
>>>>>    }
>>>> don't do that in destructors. `_columns` field can be already collected
>>>> by GC.
>>>
>>> Last I checked, the GC finalizes all dead objects before freeing them.
>>
>> The GC is not guaranteed to finalize them all before freeing them all.
>>
>> I would not count on that property -- even if it's currently true.
>> Expect that any GC-allocated memory in your dtor is invalid except for
>> the memory of the object itself.
>
> That's disappointing because it makes destructors considerably less
> useful. I think that at this point, this will probably become a
> guarantee for compatibility with existing code.

destructors are *strictly* for freeing non-GC resources. That has been 
in the spec from Day 1 (well, at least the earliest I can remember), and 
it's the same for other GC-based systems as well, such as Java.

I don't want to say that making this requirement would hinder 
performance, but I'd hate to lock us into the current GC model, as it 
pretty much sucks performance-wise. I'd rather keep as many options open 
as possible, to allow GC tinkering for performance.

-Steve


More information about the Digitalmars-d-learn mailing list