Who wants to have some fun memory debugging?

Robert Fraser fraserofthenight at gmail.com
Tue May 12 20:28:20 PDT 2009


Running this program with Tango SVN + DMD 1.045 or Tango 0.98 + DMD 
1.041 on WinXP SP3 32-bit results in a memory leak (the program keeps 
increasing in size at every iteration)

leak.d:
-------------------------------------------
module leak;

import tango.stdc.stdio;
import tango.core.Memory;

struct Data
{
	Data* prev;
	char[4092] something;
}

public void main()
{
	Data* data;
	Data* newData;
	int i;
	while(true)
	{
		for(i = 0; i < 10_000; i++)
		{
			newData = new Data;
			newData.prev = data;
			data = newData;
		}
		data = null;
		newData = null;
		i = 0;
		GC.collect();
		printf("Iteration...");
		fflush(stdout);
		fgetc(stdin);
	}
}
-------------------------------------------

Running it through a debugger shows that at the printf, the entire 
contents of the stack frame of main is zeros and there's no global data 
referenced by the program.


More information about the Digitalmars-d-learn mailing list