memory leaks in phobos?

Andrey vangelisforever at yandex.ru
Wed Apr 10 22:04:22 PDT 2013


Hello!
I'm using Debian 7 system and dmd 2.062.

I use some array functions to test memory allocation process in D 
and
have a segmentation fault as a result of this test.

How it works:

  1 iteration.
      Before allocation we have over 9.5 Mb of virtual memory used.
      After allocation we have over 582 Mb used.
      After disposing the used memory stays over 582 Mb.
  2 iteration.
      Before allocation we have over 582 Mb of virtual memory used.
      After allocation we have over 1.1 Gb used.
      After disposing the used memory stays over 1.1 Gb Mb.
  3 iteration.
      Before allocation we have over 1.1 Gb of virtual memory used.
      After allocation we have over 1.7 Gb used.
      After disposing the used memory stays over 1.7 Gb Mb.

  and so on..

result: crash application

Why "arr.length = length" allocate a new memory block at the 
second and other iterations, if before it used "clear(arr)" and 
"arr.length=0" function ?

<===EXAMPLE=====================================================>

	writeln("Before allocation. Press a key.");
	stdin.readln();

	int arr[];
	int length = 100_000_000;
	for (int i=0; i<10; i++)
	{
		arr.length = length; // always new memory blocks, why?
		arr[90] = 20;
		writeln("After allocation. Press a key.");
		stdin.readln();

		clear(arr);
		arr.length = 0; // must be deallocation? but nothing happens

		writeln("After disposing. Press a key.");
		stdin.readln();

	}

<===============================================================>

With many thanks.


More information about the Digitalmars-d-learn mailing list