Bug 20438 – [Reg 2.086] GC: memory not reusable when calling GC.collect after GC.free

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-12-07T19:58:50Z
Last change time
2019-12-08T10:13:36Z
Keywords
pull
Assigned to
No Owner
Creator
Rainer Schuetze

Comments

Comment #0 by r.sagitario — 2019-12-07T19:58:50Z
Reported in the learn forum: This program shows increasing memory usage even though allocated memory is freed manually: version=FREE; version=COLLECT; import std.stdio; import core.memory; immutable int[] intZ = [1,2,3,4,4,6,6,8,8,65,8,23]; void main() { writeln(GC.stats); enum max = 100000; foreach (i; 0 .. max) { bool doprint = !(i % (max/10)); int[] z = intZ.dup; if (doprint) writef("%7d ", GC.stats.usedSize); version(FREE) GC.free(cast(void*) z.ptr); version(COLLECT) GC.collect(); if (doprint) writefln("%7d", GC.stats.usedSize); } } This doesn't happen when either version FREE or COLLECT is not defined.
Comment #1 by r.sagitario — 2019-12-07T20:19:42Z
Reduced: import core.stdc.stdio; import core.memory; void main() { printf("1: %lld\n", cast(ulong)GC.stats.usedSize); void* z = GC.malloc(100); printf("2: %lld\n", cast(ulong)GC.stats.usedSize); GC.free(z); printf("3: %lld\n", cast(ulong)GC.stats.usedSize); GC.collect(); printf("4: %lld\n", cast(ulong)GC.stats.usedSize); } shows: 1: 16 2: 144 3: 16 4: 4096
Comment #2 by dlang-bot — 2019-12-07T21:19:30Z
@rainers created dlang/druntime pull request #2858 "fix issue 20438 - [Reg 2.086] GC: memory not reusable when calling GC…" fixing this issue: - fix issue 20438 - [Reg 2.086] GC: memory not reusable when calling GC.collect after GC.free fix detection of page with unused allocation slots https://github.com/dlang/druntime/pull/2858
Comment #3 by dlang-bot — 2019-12-08T10:13:36Z
dlang/druntime pull request #2858 "fix issue 20438 - [Reg 2.086] GC: memory not reusable when calling GC…" was merged into stable: - 7afdd5712c9299ef274ec148f83a4c98a5cc75c3 by Rainer Schuetze: fix issue 20438 - [Reg 2.086] GC: memory not reusable when calling GC.collect after GC.free fix detection of page with unused allocation slots https://github.com/dlang/druntime/pull/2858