Dynamic array leak?
bitwise via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 11 15:36:27 PDT 2017
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
More information about the Digitalmars-d
mailing list