Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convience Methods and Collections



Ryan Marsh wrote on Friday, March 30, 2007:
>Yes rootNode is a dictionary. Thanks for your help, it must be that  
>something else is wrong. I'll look in to NSZombie and ObjectAlloc.

While we're on the subject, another trick I often use is a "sacrificial object". I'll create a subclass of NSObject that overrides retain, autorelease, and release. (Or, I'll override these in an existing class I'm having problems with.) Something like this:

- (id)retain
{
    return ([super retain]);
}
- (void)release
{
    [super release];
}
...

I then throw an autoreleased instance of this object into a collection.

The only purpose here is that I can now set a breakpoint at release and use the debugger to see when and where the object is getting released. This is sometimes faster than trying to plow through an ObjectAlloc graph.

>The only difference between it working and not working is when I use  
>initWith... vs. arrayWith. My gut tells me (having limited knowledge  
>of Objective-C) that using the alloc and initWith would be an over- 
>retain when adding to a collection. But faced with the results of  
>this test I was confused... and still am.

Your gut is correct. Unless you later release or autorelease an object created with alloc+init, it will be overretained.

>Like you said, it must be something else.

Good luck,

James

-- 
James Bucanek
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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/email@hidden

This email sent to email@hidden

References: 
 >Re: Convience Methods and Collections (From: Ryan Marsh <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.