Re: NSPopUpButton failure after adding file names
Re: NSPopUpButton failure after adding file names
- Subject: Re: NSPopUpButton failure after adding file names
- From: publiclook <email@hidden>
- Date: Thu, 15 May 2003 21:23:47 -0400
On Thursday, May 15, 2003, at 07:41 PM, Rick Anderson wrote:
On Thursday, May 15, 2003, at 09:18 AM, Jonathan E. Jackel wrote:
[deleted]
On a side note, I wonder (without trying to sound too much like a
exasperated Cocoa newbie) if this issue is documented anywhere on
Apple's site. I've read quite a bit at Apple's site and elsewhere
about memory management in Cocoa (i.e., retain, release, autorelease,
etc.) and not once have I run across any warnings or explanations
about the problem with performing an extra autorelease on an object. I
guess it's entirely possible that it should be obvious to me, but
having spent nearly an hour trying to remedy something that, as far as
I know, isn't explained anywhere in Apple's documentation, it really
grates on my nerves a bit.
In Apple's introduction to Cocoa with Objective-C at the following URL:
http://developer.apple.com/techpubs/macosx/Cocoa/ObjectiveC/2objc_oop/
index.html
I read the following text:
<Quote>
Ideally a body of code should never be concerned with releasing
something it didnt create. Cocoa therefore sets this policy:
If you
create an object (using alloc or allocWithZone:)
copy an object (using copy, copyWithZone:, mutableCopy or or
mutableCopyWithZone:)
retain an object (using [retain])
then you must release it (using [release] or [autorelease]).
If you did not directly create or copy the object as described above,
you do not own it and should not release [or autorelease] it.
<End Quote>
That seems clear to me. In your problematic code, did you explicitly
allocate, copy, or retain the object that you released ? If the answer
is no then you should not have released it. It is that simple.
I might add that the book I quoted is also on your hard disk.
I further refer you to the following Stepwise articles:
http://www.stepwise.com/Articles/Technical/MemoryManagement.html Memory
Management with Cocoa/WebObjects - Manu Iyengar (memory
allocation/deallocation/collection)
http://www.stepwise.com/Articles/Technical/2001-03-11.01.html Very
simple rules for memory management in Cocoa - mmalcolm crawford
(memory allocation/deallocation/collection)
http://www.stepwise.com/Articles/Technical/2002-10-13.01.html
Conventions: What's in a name? - Erik Buck (Cocoa naming conventions)
http://www.stepwise.com/Articles/Technical/HoldMe.html Hold Me, Use Me,
Free Me - Don Yacktman (memory allocation/deallocation/collection)
http://www.stepwise.com/Articles/Technical/2000-03-03.01.html
Delegating Authority - Cocoa Delegation and Notification - Erik M. Buck
(using delegates and NSNotification)
http://www.stepwise.com/Articles/Technical/ApplicationStorage.html
Storing your application's preferences and support files - Scott
Anguish (NSDefaults and finding/storing preference files)
http://www.stepwise.com/Articles/Technical/FreezeDriedObjects.html
Freeze Dried Objects - Don Yacktman (archving and restoring objects)
There are many other fine articles at that site as well as the 1200
page "Cocoa Programming" written by the editors of Stepwise.
The following google search provides you with more information than you
could ever want on Cocoa's memory management conventions:
http://www.google.com/search?as_q=apple+cocoa+&num=100&hl=en&ie=ISO-
88591&btnG=Google+Search&as_epq=memory+management
Be warned that this O'Reilly link states some incorrect things about
collections:
http://www.macdevcenter.com/lpt/a/2848
Memory management conventions of Cocoa are not the only conventions
that you need to learn to use Cocoa effectively. The information you
need is thoughtfully presented in Apple's getting started with Cocoa
section and documented again in every single book on Cocoa (I think I
have them all).
_______________________________________________
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.