Re: Methods that return autoreleased objects?
On Jun 29, 2008, at 9:42 AM, Mike Ferris wrote: And, as long as we're on the topic... who can name the only other exceptional case for the release only if you alloc,new, copy or retain rule? (It's pretty old-school...) How about if you're implementing an initializer for a class cluster that decides, perhaps based on parameters, that it wants to return an instance of a subclass instead of self? On Jun 28, 2008, at 9:14 PM, Omar Qazi wrote: Well theres no way to know, unless it's specifically mentioned in the documentation, but it really shouldn't matter. If you need the object retain it, if you don't let someone else worry about it. This will keep you from crashing in the short term, but if you never take the time to crack this and learn to match all your retaining calls with releases, your application is doomed to die a slow leaky death. Perhaps I'm misinterpreting you... -Tom ___ 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]
Re: Methods that return autoreleased objects?
On Jun 28, 2008, at 9:59 PM, Charles Srstka wrote: Methods that begin with alloc or new or contain copy will return objects you are responsible for. All other objects returned from methods are taken care of. Well, there is the notable exception of top-level objects loaded from a NIB file, which do need to be released. ... which is documented: http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_3.html# mmalc ___ 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]
Re: Methods that return autoreleased objects?
On Jun 29, 2008, at 1:58 AM, mmalc crawford wrote: On Jun 28, 2008, at 9:59 PM, Charles Srstka wrote: Methods that begin with alloc or new or contain copy will return objects you are responsible for. All other objects returned from methods are taken care of. Well, there is the notable exception of top-level objects loaded from a NIB file, which do need to be released. ... which is documented: http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/chapter_3_section_3.html# mmalc Yes, but it's not obvious, which is why I thought to point it out since we're discussing the times when you should and shouldn't release objects. The alloc, init, and retain methods are also documented, but that doesn't mean we can't help people out with them, does it? I just think that the standard release something only if you inited or retained it advice should be amended to release something only if you inited or retained it, or if you got it from a NIB. I know this confused *me* back when I was starting out, so I just thought I'd throw that out there. Charles ___ 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]
Re: Methods that return autoreleased objects?
On Jun 29, 2008, at 8:02 AM, Charles Srstka wrote: Yes, but it's not obvious, which is why I thought to point it out since we're discussing the times when you should and shouldn't release objects. The alloc, init, and retain methods are also documented, but that doesn't mean we can't help people out with them, does it? I just think that the standard release something only if you inited or retained it advice should be amended to release something only if you inited or retained it, or if you got it from a NIB. No, it shouldn't. Because exactly what you do with objects you get from a nib depends on a number of factors. The memory management guide itself has a complete article on the subject: http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemMgmtNibObjects.html which any Cocoa developer should have read as part of the fundamentals. The basic memory management rules are simple and straightforward, and should be preserved as such -- simple and straightforward as they are they still seem to cause enough confusion. mmalc ___ 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]
Re: Methods that return autoreleased objects?
Best thing to do about the top-level nib exception to the rule is to use NSWindowController or NSViewController to do your nib loading. These classes properly take responsibility for top-level objects of the nibs they load and then all you have to do is manage the lifetime of the controller object as you normally would. And, as long as we're on the topic... who can name the only other exceptional case for the release only if you alloc,new, copy or retain rule? (It's pretty old-school...) Mike Ferris ___ 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]
Re: Methods that return autoreleased objects?
On Sat, Jun 28, 2008 at 5:25 PM, john muchow [EMAIL PROTECTED] wrote: The last thread that I saw on this topic was dated sometime in 2004if there is something more recent that I didn't find, I apologize up front... I realize nothing has probably changed as far as the API and the documentation to indicate autoreleased methods, however, can someone provide any insight as to how one knows if a method from a framework returns an autoreleased object? Who cares if it is autoreleased? That is essentially an implementation detail in most situations. Just learn the memory management rules, mix in common sense, look for exceptions to the rules (very seldom do any exist) and follow the rules in your own code. http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html -Shawn ___ 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]
Re: Methods that return autoreleased objects?
On Jun 28, 2008, at 5:25 PM, john muchow wrote: The last thread that I saw on this topic was dated sometime in 2004if there is something more recent that I didn't find, I apologize up front... I realize nothing has probably changed as far as the API and the documentation to indicate autoreleased methods, however, can someone provide any insight as to how one knows if a method from a framework returns an autoreleased object? Methods that begin with alloc or new or contain copy will return objects you are responsible for. All other objects returned from methods are taken care of. More information here: http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html Regards Markus -- __ Markus Spoettl smime.p7s Description: S/MIME cryptographic signature ___ 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]
Re: Methods that return autoreleased objects?
Don't think about it. If memory management confuses you in any way, don't try to think about the status of objects returned from framework methods. Only worry about it from the perspective of your code. Do you need the object to stay around after your method returns? Then retain it, and remember to release it somewhere else as appropriate. If you make an object with +alloc or -copy, then you'll need to release it somewhere too. In practice, most framework methods return autoreleased objects (if the method creates it). There are other situations, for example: -[NSArray objectAtIndex:] will return an object that is retained by the array, and is not in any autorelease pools (unless you've put it in one). But that's because the object was not created by the array. Bottom line: don't think about it. Follow the rules in your own code, and all will be well. Owen ___ 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]
RE: Methods that return autoreleased objects?
Oops. Sorry for the double reply. Stupid phone doesn't have a threaded view. -Original Message- From: Shawn Erickson [EMAIL PROTECTED] Sent: Saturday, June 28, 2008 5:32 PM To: john muchow [EMAIL PROTECTED] Cc: cocoa-dev@lists.apple.com cocoa-dev@lists.apple.com Subject: Re: Methods that return autoreleased objects? On Sat, Jun 28, 2008 at 5:25 PM, john muchow [EMAIL PROTECTED] wrote: The last thread that I saw on this topic was dated sometime in 2004if there is something more recent that I didn't find, I apologize up front... I realize nothing has probably changed as far as the API and the documentation to indicate autoreleased methods, however, can someone provide any insight as to how one knows if a method from a framework returns an autoreleased object? Who cares if it is autoreleased? That is essentially an implementation detail in most situations. Just learn the memory management rules, mix in common sense, look for exceptions to the rules (very seldom do any exist) and follow the rules in your own code. http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html -Shawn ___ 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/omar%40hellogalaxy.com This email sent to [EMAIL PROTECTED] ___ 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]
Re: Methods that return autoreleased objects?
On Jun 28, 2008, at 7:43 PM, Markus Spoettl wrote: Methods that begin with alloc or new or contain copy will return objects you are responsible for. All other objects returned from methods are taken care of. Well, there is the notable exception of top-level objects loaded from a NIB file, which do need to be released. Charles ___ 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]