[Gc] memory leak in C++ (part II)

S M Ryan wyrmwif at rawbw.com
Thu Jan 31 06:26:47 PST 2008


> Yesterday I sent one code fragment that I think that have an memory  
> leak,
> then Bruce help-me to understand that the code don't have a memory  
> leak.
> Than today I tried generate an new code fragment in C++ (using new  
> operator)
> with an leak that generate an gc.log that show leak, but I have no  
> success.

If you retain a pointer to the memory, it is not a leak.
	Objptr p[n]; for (i=0; i<n; i++) p[i] = new Obj;
Because p[i] is available on the stack and has a pointer, it is not a  
leak.

	for (i=0; i<n; i++) new Obj;
This does not retain all the pointers (maybe one or two in  
registers), so the lost pointers are leaks if not collected.



More information about the Gc mailing list