What's supposed to happen when using an object after FreeAndNil?

后端 未结 6 1838
轻奢々
轻奢々 2021-01-02 13:01

In my Delphi7 this code

var MStr: TMemoryStream;
...
FreeAndNil(MStr);
MStr.Size:=0; 

generates an AV: Access violation at address 0041D6D1

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 13:32

    Thomas Mueller: have you tried virtual class methods? A constructor is sort of a virtual method but you call it against the type - not the instance. This means that even some specific virtual methods will not cause AV on a null-reference :D

    Vegar: You couldn't be more right! FastMM is the best ever ever ever tool that helped me tracking down this kind of bugs.

提交回复
热议问题