[Lazarus] Help debugging

Martin lazarus at mfriebe.de
Wed Jan 11 18:33:44 CET 2012


On 11/01/2012 17:26, Kjow wrote:
> about threads: your question (if my program is multithread) turned on
> a light bulb over my head, the problem was that I freed the same
> object in two different threads... (main thread and "cadencer") and I
> think that it should behave something like:
>
> "
> if assigned(MyObj) Then
>    begin
>      freeandnil(MyObj);
>      MyObj.Destroy;
>    end;
> "

The above will free it twice => always crash.

>
> instead of:
>
> "
> if assigned(MyObj) Then
>    freeandnil(MyObj);
>
> if assigned(MyObj) Then
>    MyObj.Destroy; //of course this was wrong anyway.
> "
>

accessing a variable like that, requires a critical section. Or any 
other kind of lock ...

also no other thread must be inside any method of this object, as then 
"self" is a local copy of the pointer (self does not get nil, but yet 
the object will be gone)

same for any other local copy....





More information about the Lazarus mailing list