[fpc-pascal]Memory leak in freepascal, FreeAndNil not working properly?
memsom at interalpha.co.uk
Wed Jun 23 17:58:04 CEST 2004
> > You code is wrong, it also crashes with kylix.
> What kind of answer is this?
The correct one?
To remove an item from a TList you must:
(a) set it to nil and pack the list
list := nil;
(b) call TList.Delete(index)
(c) use TList.Remove(pointer)
Did the explanation not make sense? You obviusly do not understand how
pointers wor... right? A pointer points to a memory address. Setting a
pointer to nil, does not remove that block of memory from existance... for
a, b: TObject;
a := TObject.Create;
b := a; //b points at a
//at this point, b still points to the memory allocated to a, but this
memory is no longer valid, and it will A/V if you free b
b.free; //access violation...
Do you understand now?
More information about the fpc-pascal