Simon Carter wrote:
If an exception were to be raised then you could potentially leak memory,
you should but the Tlist in a try/finally block:
list := Tlist.Create();
try
...
finally
list.Free();
end;
Being exception-safe in this case is more complicated than that. You
need to free the items that are in the list before you free the list.
There are some other complications, such as whether to free an item when
an exception occurs while trying to add it to the list, that depend on
the context of the code you're trying to protect. What happens between
the "try" and the "finally" is important.
If you want to worry about freeing the items in the list, then the best
thing to do is to write a descendant of TList and override its
Notification method. That's what TObjectList does to free its contents
when its OwnsObjects property is True.
Of course, unless you *catch* the exception somewhere, handle it, and
continue running the program, it doesn't matter whether you free anything.
--
Rob
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk