memory leaks in phobos?
Ali Çehreli
acehreli at yahoo.com
Wed Apr 10 23:55:41 PDT 2013
On 04/10/2013 10:04 PM, Andrey wrote:> Hello!
> int arr[];
> int length = 100_000_000;
> for (int i=0; i<10; i++)
> {
> arr.length = length; // always new memory blocks, why?
The slice does not know what other slices may be sharing the same
elements. So, increasing the length of a slice will relocate the
elements (almost always, with exceptions.) The following article goes
into a lot of detail:
http://dlang.org/d-array-article.html
> arr[90] = 20;
> writeln("After allocation. Press a key.");
> stdin.readln();
>
> clear(arr);
> arr.length = 0; // must be deallocation? but nothing happens
Are you compiling as a 32-bit application? Then, chances are random bit
patterns look like references into these slices. (dmd uses a
conservative garbage collector). Try compiling with -m64.
Ali
More information about the Digitalmars-d-learn
mailing list