FROM : Bill Bumgarner
DATE : Mon Jun 02 22:50:16 2008
On Jun 2, 2008, at 11:40 AM, mmalc crawford wrote:
> On Jun 2, 2008, at 10:50 AM, Bill Bumgarner wrote:
>> If your window is sometimes disappearing under GC -- is sometimes
>> being collected prior to when you think it should be -- that means
>> that the collector doesn't believe that the window object is being
>> used by your application. To the collector, being visible doesn't
>> count as "in use".
>> In GC, "in use" is defined entirely by whether or not you have a
>> reference to an object. A pointer to the object somewhere in
>> scanned memory (of which, any Objective-C object's data will be
>> "scanned memory").
>>
> I wonder if this might be misleading.
> Simply because you have a (strong) reference to an object does not
> *necessarily* mean that it won't be treated as garbage.
>
> Several objects may have strong references to each other (creating
> what in a managed memory environment would be a retain cycle), but
> if none of them is a root object, and none of them can be reached
> via strong references from a root object, then they will all be
> treated as garbage -- see the "F-G-H" example at <http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcEssentials.html
> >.
You are absolutely correct. The collector will happily collect
strongly referenced subgraphs of objects when the only strong
references are within the subgraph.
You need to have a rooted reference to an object to ensure that it is
not collected. That is, you need to refer to an object -- directly or
indirectly through a chain of strong references -- via a strong
reference from some object that the collector will not collect.
Under Cocoa, that typically means NSApplication or some global
variable. For example, NSApplication has a delegate [strong reference
under GC] and your delegate could have a connection to the window
[strong reference].
b.bum
DATE : Mon Jun 02 22:50:16 2008
On Jun 2, 2008, at 11:40 AM, mmalc crawford wrote:
> On Jun 2, 2008, at 10:50 AM, Bill Bumgarner wrote:
>> If your window is sometimes disappearing under GC -- is sometimes
>> being collected prior to when you think it should be -- that means
>> that the collector doesn't believe that the window object is being
>> used by your application. To the collector, being visible doesn't
>> count as "in use".
>> In GC, "in use" is defined entirely by whether or not you have a
>> reference to an object. A pointer to the object somewhere in
>> scanned memory (of which, any Objective-C object's data will be
>> "scanned memory").
>>
> I wonder if this might be misleading.
> Simply because you have a (strong) reference to an object does not
> *necessarily* mean that it won't be treated as garbage.
>
> Several objects may have strong references to each other (creating
> what in a managed memory environment would be a retain cycle), but
> if none of them is a root object, and none of them can be reached
> via strong references from a root object, then they will all be
> treated as garbage -- see the "F-G-H" example at <http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcEssentials.html
> >.
You are absolutely correct. The collector will happily collect
strongly referenced subgraphs of objects when the only strong
references are within the subgraph.
You need to have a rooted reference to an object to ensure that it is
not collected. That is, you need to refer to an object -- directly or
indirectly through a chain of strong references -- via a strong
reference from some object that the collector will not collect.
Under Cocoa, that typically means NSApplication or some global
variable. For example, NSApplication has a delegate [strong reference
under GC] and your delegate could have a connection to the window
[strong reference].
b.bum






Cocoa mail archive

