realbasic-nug
[Top] [All Lists]

Re: Circular reference powers used for good?

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Circular reference powers used for good?
From: James Sentman <james at sentman dot com>
Date: Mon, 31 Dec 2007 17:22:12 -0500
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <1F31400A-2192-40FA-B482-EAAD05F0C530 at oxalyn dot com> <31becf620712310609n6bc59eebt909110f741481fc7 at mail dot gmail dot com> <3C9E9382-6D09-482B-AD65-6A017E856616 at oxalyn dot com>
On Dec 31, 2007, at 10:07 AM, Eric Williams wrote:

>> Assuming Window1 doesn't go out of scope, objects A through F will
>> all be
>> available. If you then destroy the Window1->ObjD reference, objects
>> D-F --
>> even though they reference each other -- are no longer available
>> and will be
>> destroyed. This, of course, assumes you don't have any other
>> references
>> somewhere.
>


I'd have to run some tests to see if this was true, I can say that  
historically this has NOT been true and would have been an upgrade  
somewhere to the reference counting system.

But apart from that I agree that this particular use of circular  
references might be fishy ;) That being said there is nothing wrong  
with circular references! I use them all the time for similar things,  
a timer that stores a reference to it's socket for example so that it  
can signal a timeout and the socket maintains a reference to the timer  
so that it can cancel or reset it. This is a circular reference and if  
you just kill the socket and set it's reference in whatever list you  
hold them in to nil that socket and it's timer will hang around lost  
in memory forever because they still reference each other. Just  
because you no longer have a way to get to those references doesn't  
make then any less valid as far as reference counting is concerned.

You just need to have close or other methods that you can use to break  
the references and set them to nil. And you cannot use the destructor  
methods for this as they will only fire once all references have  
already been destroyed by something else. So circular references are  
both good, valid and sometimes necessary, you just have to remember to  
break them yourself.


Thanks,
  James


James Sentman                       http://sentman.com          
http://MacHomeAutomation.com



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

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


<Prev in Thread] Current Thread [Next in Thread>