On Tue, Jan 19, 2010 at 2:38 PM, Graham Cox <[email protected]> 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 protected])

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]

Reply via email to