Or you could simply set the parent reference to nil in Egg::~Egg()  
(i.e. the destructor.) Now when the EggCarton doesn't need an Egg  
instance anymore, it just sets it to nil, and allows it to die. The  
Egg's destructor will be called before the Egg goes >splat!< and you  
won't have to worry about weak references. This should work in any  
version of RB...
   Just don't destroy the Egg instance anywhere near your Car  
instance, or you'll have to call myCar.PaintJob.Clean()!! :)


On Apr 11, 2007, at 6:05 AM, Mathieu Langlois wrote:

> That's the idea.  If your Eggs have a weak reference to the carton,  
> then you
> don't need to worry about anything, when the carton gets out of  
> scope in
> your code, it will get destroyed along with all the eggs it contains.
>
> Math
>
> On 4/11/07, Stephen Dodd <[EMAIL PROTECTED]> wrote:
>>
>> Are circular references never destroyed and garbage collected?
>>
>> In Aaron's nice little intro to 2007r2
>> (
>> http://www.rblibrary.com/rblibrary/index.php? 
>> main_page=product_info&products_id=81
>> ),
>> he mentions the dangers of circular references stopping objects from
>> being destroyed (and the use of WeakRef to get around it.)
>>
>> Let's look at an example:
>>
>> EggCarton object contains 12 Egg objects (as properties)
>> Each Egg contains a reference to the parent EggCarton
>>
>> If my program creates and destroys EggCartons containing Eggs, will I
>> 'leak' memory unless I use WeakRef?  (Assume only the EggCarton
>> references Eggs.)
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to