Skip navigation.
 
mlRe: Main window disappears. Sometimes.
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

Related mailsAuthorDate
mlMain window disappears. Sometimes. Francis Perea Jun 2, 09:58
mlRe: Main window disappears. Sometimes. Wayne Packard Jun 2, 10:06
mlRe: Main window disappears. Sometimes. Francis Perea Jun 2, 10:36
mlRe: Main window disappears. Sometimes. Michael Vannorsdel Jun 2, 10:45
mlRe: Main window disappears. Sometimes. Francis Perea Jun 2, 11:05
mlRe: Main window disappears. Sometimes. Michael Vannorsdel Jun 2, 11:19
mlRe: Main window disappears. Sometimes. Paul Sargent Jun 2, 11:50
mlRe: Main window disappears. Sometimes. Graham Cox Jun 2, 13:11
mlRe: Main window disappears. Sometimes. Francis Perea Jun 2, 13:16
mlRe: Main window disappears. Sometimes. Francis Perea Jun 2, 13:24
mlRe: Main window disappears. Sometimes. Michael Vannorsdel Jun 2, 19:31
mlRe: Main window disappears. Sometimes. Bill Bumgarner Jun 2, 19:50
mlRe: Main window disappears. Sometimes. Paul Sargent Jun 2, 20:35
mlRe: Main window disappears. Sometimes. mmalc crawford Jun 2, 20:40
mlRe: Main window disappears. Sometimes. Paul Sargent Jun 2, 20:55
mlRe: Main window disappears. Sometimes. Francis Perea Jun 2, 22:48
mlRe: Main window disappears. Sometimes. Bill Bumgarner Jun 2, 22:50
mlRe: Main window disappears. Sometimes. Henry McGilton (St… Jun 3, 04:19
mlRe: Main window disappears. Sometimes. William Bumgarner Jun 3, 04:47
mlRe: Main window disappears. Sometimes. Michael Ash Jun 3, 06:50
mlRe: Main window disappears. Sometimes. Sean McBride Jun 3, 17:28
mlRe: Main window disappears. Sometimes. Stephane Sudre Jun 3, 18:20
mlRe: Main window disappears. Sometimes. Bill Bumgarner Jun 3, 18:29
mlRe: Main window disappears. Sometimes. Stephane Sudre Jun 3, 18:56
mlRe: Main window disappears. Sometimes. Andy Lee Jun 3, 19:02
mlRe: Main window disappears. Sometimes. Hamish Allan Jun 3, 19:22
mlRe: Main window disappears. Sometimes. Bill Bumgarner Jun 3, 19:25