On Tue, Jan 10, 2017 at 6:14 AM, Michael Schnell <mschn...@lumino.de> wrote:
> > If destroying an object is not necessary, the class should provide a dummy > Free procedure. So the application programmer always can/should use Free. > > Why dummy? if it should be like this procedure TObject.Free; begin if Self<>nil then Self:=nil; end; Destroying object is not necessary, but dereferencing is. If the code keeps the reference to an object, it would not be collected. For example. In pascal: var b : TSomeClass; begin b := TSomeClass.Create; // allocated .. b.Free; // freed (b becomes an invalid pointer) ... end. JVM with dummy Free var b : TSomeClass; begin b := TSomeClass.Create; // allocated .. b.Free; // does nothing (b remains a valid pointer) ... end.// a might be freed after leaving the scope of visibility JVM with nil-ing Free. var b : TSomeClass; begin b := TSomeClass.Create; // allocated .. b.Free; // derefering a, (a, become nil) ... // a might be Freed here somewhere, whenever gc occurs end. thanks, Dmitry
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal