Re: [Newbie] reference count
Re: [Newbie] reference count
- Subject: Re: [Newbie] reference count
- From: "John C. Randolph" <email@hidden>
- Date: Fri, 16 May 2003 11:37:33 -0700
On Friday, May 16, 2003, at 06:53 AM, kunikyo wrote:
[Newbie] reference count
Hello all,
Now I am reading "Cocoa Programming" by Scott Anguish, et al.
and having a basic question about reference count that
I'm hoping people can answer.
On page 223〜page 272, I have found following two questions on a sample
program.
I traced the opening sequence and found successive allocWithZone
twice, and
_myOpenDocuments is not released after the Quit of the sample program.
The first question is about the following message.
_myOpenDocuments = [[NSMutableArray allocWithZone:[self zone]] init];
This message is called in -init and -awakeFromNib, so this message is
called
twice at the opening sequence.
Is it permitted that allocWithZone of the same array is called twice?
Reference count kept 1 after twice call of allocWithZone.
I think that we need allocWithZone of -awakeFromNib but
we do not need allocWithZone of -init.
The allocWithZone of -init does not make sense to me.
The second question is that _myOpenDocuments was not released
after all.
We find [_myOpenDocuments release]; in - (void)dealloc,
but this was not invoked after selecting Quit on menu.
I am afraid of memory leak.
It's not an issue if the program is quitting. When any Mac OS X app
terminates, its memory gets reclaimed. -retain/-release is only needed
for memory management while the app is still running.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.