Re: Main window disappears. Sometimes.
Re: Main window disappears. Sometimes.
- Subject: Re: Main window disappears. Sometimes.
- From: Bill Bumgarner <email@hidden>
- Date: Mon, 02 Jun 2008 10:50:13 -0700
On Jun 2, 2008, at 10:31 AM, Michael Vannorsdel wrote:
On Jun 2, 2008, at 5:24 AM, Francis Perea wrote:
Hi Graham, thanks for your reply.
I didn't know I could set any memory setting trough Interface
Builder!
After your question I looked into and I've seen that it states as
Beffered.
I've tried to use the Retained option, thinking that this way I
shouldn't use the retain message, but with Retained the windows
appears but doesn't accept any interaction.
I'd take a deep look into de Memory Management doc you suggest.
While learning the retain/release paradigm is certainly useful, it is
considerably more complex than GC. It is also unnecessary while
learning Cocoa. Specifically, GC is intended to be a production
quality solution that you can use in your Cocoa applications, without
exception. In Leopard, there have been a handful of bugs and they
have been addressed through software updates -- not surprising given
the rather sweeping and intrusive set of changes needed to support
GC. And GC will get better / faster in future releases.
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").
So, when your NIB is loaded, who hangs on to a reference to the
window. It doesn't sound like anything does. The easiest way to fix
this would be to create an outlet in your file's owner and connect
that outlet as a reference to the window. Now, as long as the file's
owner has a strong reference to *it*, then your window sticks around.
Note that in document based applications, the NSDocument
infrastructure takes care of keeping things referenced that need to
stick around.
This sounds like you have a non-document based application and your
main window is disappearing out from under you. From the documentation:
Since the collector follows strong references from root objects,
and treats as garbage all objects that cannot be reached from a
root object, you must ensure that there are strong references to
all top-level objects in a nib file (including for example, stand-
alone controllers)—otherwise they will be collected. You can
create a strong reference simply by adding an outlet to the
File's Owner and connecting it to a top-level object. (In
practice this is rarely likely to be an issue.)
b.bum_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden