On Wed, May 21, 2008 at 12:47 PM, Peter Hudson <[EMAIL PROTECTED]> wrote:
> The line of code [NSArray arrayWithObjects: c0, ...c9, nil]; produces > an array all right - but as you have used a class initializer, it will auto > release > when you return from the method where it was created. No, because you have used a method other than the handful of listed exceptions to the general rule, the array is not your responsibility to release. It may be autoreleased, it may be a singleton, there may be some other magic going on - you don't know and shouldn't care about which is actually the case. > Any initialiser with a "+" in front of it returns an autoreleased object Nonsense. Initializers begin with -init, and they're called to initialize objects created with +alloc. And some class methods (+alloc again, and +allocWithZone, and +new) do carry with them the responsibility of a later matching release. > - hence you MUST retain them or else they are simply released > when the autorelease pool they are created in is released - which you can > treat > as occurring at the end of the method in which the init occurs. Nonsense again. The autorelease pool is emptied at the end of each iteration through the event loop, and each iteration can encompass any number of method calls. > Do it like this [ [NSArray arrayWithObjects: c0, ...c9, nil] retain]; > > and then it will stay around until you send it a release message, > probably in the dealloc method; > > [cityArray release]; "Probably in the dealloc method"? Yet more nonsense. Retain/release logic belongs in setter methods - you release the old object before assigning a new one, and by doing so you encapsulate all of your memory management in one place, where it's easy to maintain and debug. You *seriously* need to read this: < http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html >. sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]