Managing Retain/Release for a ContentView
Managing Retain/Release for a ContentView
- Subject: Managing Retain/Release for a ContentView
- From: Joel Lachter <email@hidden>
- Date: Tue, 12 Aug 2003 10:24:51 -0700
I have an application where the documents have an additional "helper"
window, and I need a little advice on how best to release the view of
that window.
This is what I do currently. First I create a window:
exptWindow = [[ExptWindow alloc] initWithFrame:NSMakeRect(64,64,800,600)];
Then I create a view for that window (because I use alloc I get a
retain count of 1 for this view):
pmView = [[PM1View alloc] initWithFrame:[exptWindow frame]];
Then I add the view to the window (somewhat to my surprise this
increments the retain count to 2; I couldn't find that in the
documentation but if I send pmView a retainCount message it goes up
to 2 after this call):
[exptWindow setContentView: pmView];
All of these calls are within my subclass of NSDocument. Here is the
question, should I be thinking of the second retain as belonging to
my document or the window? The document already owns one reference to
pmView. I originally had the document send pmView a release message
before closing the window, it seems a little silly to be sending it
two. On the other hand, it seems strange to me to send a release
message in the window's dealloc method since the window did not
create the view. What is the correct style for this?
Thanks!
Joel
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.