What kind of sick, twisted mind calls FreeAndNil on an interface?

What kind of sick, twisted mind calls FreeAndNil on an interface?

Comments

  1. Probably the programmer has refactored from using objects to using interfaces recently and - as the parameter of FreeAndNil is typeless and no compiler hint is given - forgot to remove this. However... I've seen much worse... interface methods like "FreeOnNextReleaseCall". Guess, what it is doing? I had much fun debugging AVs due to such ingenious ideas... :-/

    ReplyDelete
  2. Somebody who changed an object reference to an interface without realizing this consequence. (Yes, I am guilty of this. It took me forever to figure out the reason for the weird AVs that were caused by this.)

    ReplyDelete
  3. @Thomas: you can rest assured as this is easy to forget doing such a refactoring (see my comment above why).

    ReplyDelete
  4. Stefan Meisner   LOL -- argh!  It was my sick twisted mind!  I changed the class to an interface.  Oh the shame!  ;-)

    Okay, this is yet another reason to never use FreeAndNil -- if Free were uses, the compiler would have let me know!  ;-)

    ReplyDelete
  5. Nick Hodges interface strikes back, part 1! ((:

    ReplyDelete
  6. Nick Hodges I was wondering when someone would say to "never us FreeAndNil" but its funny that yourself are the one ;-D

    ReplyDelete
  7. How did he live with the exception?
    Try
    FreeAndNil(intf);
    Finally
    Inherited Destroy;
    End;
    ?

    ReplyDelete
  8. Sorry guys, but for Delphi N00bs like I am , EMB doesn't show the example ...  look at the procedure procedure TMyThread.OnTerminate in the  delphi code :

    http://docwiki.embarcadero.com/CodeExamples/XE2/en/TThreadYield_(Delphi)


    Honestly, coming from the bargage collector world, all this debate about FreeAndNil let me totally...  puzzled

    ReplyDelete
  9. That is some seriously retarded thread code!

    ReplyDelete
  10. Simon Stuart have you laughed at "synchronize everything and everywhere in the thread" thing?

    ReplyDelete

Post a Comment