On Tue, Jul 6, 2010 at 12:10 PM, Andrew Brunner <andrew.t.brun...@gmail.com> wrote: >> Hum... I do not agree. Why not this? See.. >> >> obj1:=TMyObject.Create; >> obj2:=TMyObject.Create; >> Try >> Obj1.DoSomething1; >> Obj2.DoSomething2; >> Finally >> FreeAndNil(Obj1); >> FreeAndNil(Obj2); >> end; >> > > In your example, if obj2:=TMyObject.Create fails (which will happen if > resources are not available)... then the exception is raised and Obj1 > never gets freed. So in an example where this method is re-entrant, > you would see many instances of this occurring.
Better: obj1 := nil; obj2 := nil; Try obj1 := TMyObject.Create; obj2 := TMyObject.Create; obj1.DoSomething1; obj2.DoSomething2; finally obj1.Free; obj2.Free; end; The objectcs are protected. But is boring... :) Everybody codify like that, afraid if resources are not available? Marcos Douglas _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal