Re: NSDictionary trouble
Re: NSDictionary trouble
- Subject: Re: NSDictionary trouble
- From: Shawn Rutledge <email@hidden>
- Date: Tue, 19 Jan 2010 15:57:52 -0700
On Tue, Jan 19, 2010 at 2:38 PM, Graham Cox <email@hidden> wrote:
>
> On 20/01/2010, at 5:33 AM, Shawn Rutledge wrote:
>
>> I forgot to mention, another problem I ran into was that my dictionary
>> is a member variable of my UIViewController, I inited it in
>> initWithNibName, then later when I go to use it in another member
>> function, I found that it had been garbage-collected. I used other
>> member variables the same way, but only the dictionary got
>> garbage-collected. So I fixed it by doing [myDict retain]; in the
>> initWithNibName, but didn't understand why such a thing should be
>> necessary.
>
>
> Uh-oh, category error.
>
> UIViewController is an iPhone class, therefore you must be programming on iPhone, right? Which does not have garbage collection.
Oops, I guess you're right. I'm a n00b both on Objective-C and the
iphone (obviously).
> Therefore your assumptions about what is happening are wrong. You MUST learn the memory management rules and have them down pat so you can write correctly managed code without having to really think about it.
Yes I will read more about that. Anyway, the NSMutableDictionary*
member variable was inited fine, I can see that if I set a breakpoint
in the VC's init method, but by the time I use it in another member
function, it's pointing to unallocated memory. I verified that with
the NSZombie trick. But retaining the dictionary fixed it. Any idea
why?
I think dictionaryWithCapacity should both alloc and init it, right?
_______________________________________________
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