How does the GC work?

Huang F Guan gdxxhg+newsgroup at google.com
Thu Aug 23 23:17:34 PDT 2007


// A simple program
int test()
{
	int *a = new int;
	*a = 1;
	return 0;
}

int main()
{
	test();
	return 0;
}

//======================
Hi, I wonder how the gc works in my D programs. This is a test program. In the test function, I allocate a memory space for an integer pointer and don't delete it by the end of the function. I think the garbage collector will help me do this. But when I debugged my program, I couldn't find any deallocate behaviors until the end of the test function. Finally I found that gc deallocate it when the program was going to exit.

Doesn't gc deallocate the allocated momory at once when I no more use it?




More information about the Digitalmars-d mailing list