Should I put a try-finally block after every Object.Create?
Posted
by max
on Stack Overflow
See other posts from Stack Overflow
or by max
Published on 2010-05-27T16:35:53Z
Indexed on
2010/05/27
16:51 UTC
Read the original article
Hit count: 149
I have a general question about best practice in OO Delphi. Currently, I put try-finally blocks anywhere I create an object to free that object after usage (to avoid memory leaks). E.g.:
aObject := TObject.Create;
try
aOBject.AProcedure();
...
finally
aObject.Free;
end;
instead of:
aObject := TObject.Create;
aObject.AProcedure();
..
aObject.Free;
Do you think it is good practice, or too much overhead? And what about the performance?
© Stack Overflow or respective owner