POV-Ray : Newsgroups : povray.off-topic : A tale of two cities : Re: A tale of two cities Server Time
29 Jul 2024 20:13:32 EDT (-0400)
  Re: A tale of two cities  
From: clipka
Date: 14 Mar 2012 13:10:54
Message: <4f60d11e$1@news.povray.org>
Am 14.03.2012 18:07, schrieb clipka:
> Am 14.03.2012 17:57, schrieb Warp:
>
>>>> And btw, cyclic references are not the only problematic situation with
>>>> reference counting. There are cases where objects may be deleted too
>>>> early,
>>>> while there's still code using them.
>>
>>> I can't think of any reason why that could possibly happen, provided
>>> that the reference counting is implemented in a thread-safe manner.
>>
>> Module A has a reference-counting smart pointer pointing to an object B.
>>
>> A member function of that object B calls a function of module A. Said
>> function of A drops the reference to object B. Since it was the only
>> reference pointing to it, the object B gets deleted. When the function
>> in A ends, the execution returns to the member function of B, which now
>> operates on a deleted object. Undefined behavior ensues.
>>
>> Yes, that *can* happen.
>
> Hm... you do have a point there.

Then again, how would any other GC prevent this kind of thing happening? 
As soon as A drops the reference to B, the latter isn't referenced 
anymore, so if at this moment the GC happens to kick in you're still in 
for trouble. Except that now your error is even more sporadic in nature 
and therefore even more difficult to hunt down.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.