Re: Suggestions for debugging “EXC_BAD_ACCESS” [SOLVED]
Re: Suggestions for debugging “EXC_BAD_ACCESS” [SOLVED]
- Subject: Re: Suggestions for debugging “EXC_BAD_ACCESS” [SOLVED]
- From: Kyle Sluder <email@hidden>
- Date: Fri, 25 Sep 2009 16:51:06 -0700
On Fri, Sep 25, 2009 at 4:46 PM, Bob Barnes <email@hidden> wrote:
> Thank you guys. Took a little digging but the combination of NSZombie &
> instruments object allocation did the job. After years working with Java I
> find myself tripping over memory management issues much too often. I had
> allocated a UIButton using buttonWithType: and then later released it
> without ever having retained it. I'm concluding (perhaps incorrectly) that
> using buttonWithType: doesn't grant 'object ownership' in the same way that
> alloc does.
You are correct. Re-read the Memory Management Guide and commit the
rules to heart:
http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994-BAJHFBGH
Specifically, the first rule applies in this case:
"You take ownership of an object if you create it using a method whose
name begins with “alloc” or “new” or contains “copy” (for example,
alloc, newObject, or mutableCopy), or if you send it a retain message.
You are responsible for relinquishing ownership of objects you own
using release or autorelease. Any other time you receive an object,
you must not release it."
Since "buttonWithType:" does not begin with "alloc" or "new", and does
not contain "copy", you don't own the object it returns.
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden