Re: Dynamic array leak?

2017-08-14 Thread Meta via Digitalmars-d
On Saturday, 12 August 2017 at 08:16:56 UTC, Temtaime wrote: Collect - is a hit to the GC, not an order. It can ignore this request. As far as I can tell, it is an order. From the GC code[1]: void collect() nothrow { fullCollect(); } ... size_t fullCollect()

Re: Dynamic array leak?

2017-08-14 Thread Steven Schveighoffer via Digitalmars-d
On 8/12/17 4:16 AM, Temtaime wrote: Collect - is a hit to the GC, not an order. It can ignore this request. Hm.. where is this documented? I agree that the GC may not clean up all memory that could be legitimately cleaned up, but that's not because it didn't do a collection. -Steve

Re: Dynamic array leak?

2017-08-12 Thread Marco Leise via Digitalmars-d
Am Fri, 11 Aug 2017 18:44:56 + schrieb bitwise : > […] That can't work and here is why: Druntime employs a conservative GC that will treat several things as potential pointers to GC memory. From the top of my head, the entire stack as well as void[] arrays and unions

Re: Dynamic array leak?

2017-08-12 Thread bitwise via Digitalmars-d
On Saturday, 12 August 2017 at 17:52:47 UTC, Dgame wrote: [...] auto s(T, size_t n)(T[n] values) { return values; } assert(equal(a[], [S(0), S(1)].s)); This seems to work, but I'm trying to determine if it's 100% guaranteed safe. Tacking on @nogc doesn't seem to stop it from

Re: Dynamic array leak?

2017-08-12 Thread Dgame via Digitalmars-d
On Saturday, 12 August 2017 at 17:25:36 UTC, bitwise wrote: On Saturday, 12 August 2017 at 08:16:56 UTC, Temtaime wrote: Collect - is a hint to the GC, not an order. It can ignore this request. If this is the case, then D's GC should have an option to force collection like C#'s GC:

Re: Dynamic array leak?

2017-08-12 Thread bitwise via Digitalmars-d
On Saturday, 12 August 2017 at 08:16:56 UTC, Temtaime wrote: Collect - is a hint to the GC, not an order. It can ignore this request. If this is the case, then D's GC should have an option to force collection like C#'s GC: https://msdn.microsoft.com/en-us/library/bb495757(v=vs.110).aspx

Re: Dynamic array leak?

2017-08-12 Thread Temtaime via Digitalmars-d
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

Re: Dynamic array leak?

2017-08-11 Thread bitwise via Digitalmars-d
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:

Re: Dynamic array leak?

2017-08-11 Thread Yuxuan Shui via Digitalmars-d
On Friday, 11 August 2017 at 18:44:56 UTC, bitwise wrote: struct S { static int count = 0; this(int x) { ++count; } this(this) { ++count; } ~this() { --count; } } int main(string[] argv) { S[] x = [S(1), S(1)]; writeln("GC allocated: ", (GC.addrOf(x.ptr) !is null));

Dynamic array leak?

2017-08-11 Thread bitwise via Digitalmars-d
struct S { static int count = 0; this(int x) { ++count; } this(this) { ++count; } ~this() { --count; } } int main(string[] argv) { S[] x = [S(1), S(1)]; writeln("GC allocated: ", (GC.addrOf(x.ptr) !is null)); x = null; GC.collect(); writeln("live objects: ",