[Issue 2306] New: Scope for dynamic arrays should free memory.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 22 20:15:07 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2306
Summary: Scope for dynamic arrays should free memory.
Product: D
Version: 2.018
Platform: PC
OS/Version: Windows
Status: NEW
Severity: minor
Priority: P3
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: dsimcha at yahoo.com
Because of the overhead of frequent garbage collections, as well as false
pointer issues with conservative GC, it is sometimes desirable to use
RAII-style memory management for large arrays. Most RAII stuff in D is done
using the scope keyword. However, when applied to dynamic arrays, the scope
keyword apparently does absolutely nothing. The following program runs out of
memory after 3 iterations due to false pointer issues, as is expected when
allocating a 400 MB array in 4 GB address space w/ conservative GC as the only
method being used to free memory.
import std.stdio;
void main() {
uint count = 0;
while(true) {
test();
writefln(++count);
}
}
void test() {
scope uint[] foo = new uint[100_000_000];
}
However, the following actually runs indefinitely:
import std.stdio;
void main() {
uint count = 0;
while(true) {
test();
writefln(++count);
}
}
void test() {
uint[] foo = new uint[100_000_000];
scope(exit) delete foo;
}
This isn't a very serious bug, since there's an obvious, simple workaround, but
it's still an inconsistency in the language design, and ideally should be
fixed.
--
More information about the Digitalmars-d-bugs
mailing list