POV-Ray : Newsgroups : povray.off-topic : A tale of two cities : Re: A tale of two cities Server Time
26 Sep 2024 17:44:31 EDT (-0400)
  Re: A tale of two cities  
From: clipka
Date: 14 Mar 2012 12:58:57
Message: <4f60ce51$1@news.povray.org>
Am 14.03.2012 17:33, schrieb Kevin Wampler:
> On 3/14/2012 9:14 AM, clipka wrote:
>>> 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.
>
> Imagine you've implemented a tree where each node is an object which has
> a "delete" method that removes the node from the tree. If you're not
> careful the node could end up removing all references-counted pointers
> to itself (since "this" isn't reference counted) and be reclaimed while
> still running its own delete method.

It is a problem only as long as you tie object destruction to reclaiming 
of memory.

If the memory management is designed to /first/ call the destructor of 
the "payload object", and only /afterwards/ decrement the reference 
counter and release memory, then I don't see anything you'd have to fear 
from this scenario.

Problems may arise of course if you try to implement the reference 
counter management functionality in the "payload object" itself. Don't 
do that - tie the ref counter management to a dedicated pointer type.


Post a reply to this message

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