[Issue 4358] Potential Memory Leaks in std.file.read() ?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jun 21 21:55:42 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4358
nfxjfg at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nfxjfg at gmail.com
--- Comment #1 from nfxjfg at gmail.com 2010-06-21 21:55:39 PDT ---
Congratulations, you just found out that D's GC implementation is fucking shit.
There doesn't seem to be a bug in std.file.read. It just uses the GC to
allocate a big chunk of memory, and returns it. There are probably false
pointers. Note that the latest allocated buffer will not be free'd with
fullCollect() (because you still have a reference to the buffer in that
variable), but I assume imageres.dll is much smaller than 200 MB.
Rule of thumb: never allocate big arrays with the GC.
There's a patch in bug 3463 to alleviate the problem, but it seems to be
abandoned.
Though, there is one potential problem in the D2 version of std.file.read. It
contains this line:
auto buf = GC.malloc(size, GC.BlkAttr.NO_SCAN)[0 .. size];
buf is returned as void[] to the user. As far as I understand the recently
introduced changes to array appending, the memory block for an array slice
contains a hidden length field. This is not present in this case, thus random
things may happen if you try to append to the returned array. I do not know if
this actually is a problem.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list