Dynamic array leak?
Temtaime via Digitalmars-d
digitalmars-d at puremagic.com
Sat Aug 12 01:16:56 PDT 2017
On Friday, 11 August 2017 at 22:36:27 UTC, bitwise wrote:
> On Friday, 11 August 2017 at 19:01:44 UTC, Yuxuan Shui wrote:
>> On Friday, 11 August 2017 at 18:44:56 UTC, bitwise wrote:
>> [...]
>>
>> My guess is a pointer to the array still lives somewhere on
>> the stack. This gives the expected output:
>>
>> void f()
>> {
>> S[] x = [S(1), S(1)];
>> writeln("GC allocated: ", (GC.addrOf(x.ptr) !is null));
>> x = null;
>> }
>>
>> int main(string[] argv)
>> {
>> f();
>> GC.collect();
>> writeln("live objects: ", S.count);
>> return 0;
>> }
>
> Makes sense. I was uncommenting unit tests one-by-one after
> making some changes when I triggered this. I guess they were
> passing before because subsequent unit tests cleared the
> pointers off the stack. I guess I can just call a function that
> allocates a large zeroed-out array on the stack in the last
> unit test before checking the count if this happens again.
>
> Thanks
Collect - is a hit to the GC, not an order. It can ignore this
request.
Also do not rely on the gc calling a dtor - it is not safe and
can be called totally randomed, so use RC instead or expicit
destroy()
More information about the Digitalmars-d
mailing list