Rudiger
Rudiger

Reputation: 6769

Passing a dictionary from view controllers

In one of my Navigation view controllers I build an array of dictionaries to display in a table. Based on which one I select I then remove the dictionary from the array using NSDictionary *notice = [notices objectAtIndex: roomIndex];

I create the new view controller using Feed *notice_view = [[Notice alloc] initWithObject: notice];

I push the navigation view controller and I've implemented initWithObject which takes a Dictionary.

I release the notice and notice_view and all this works fine but if I selected go back, select it go back about the third or forth time the whole app crashes. If I dont release both of them it works fine no problems what so ever, except of course the memory leaks.If i only release one of them, either of them, it fails again. What gives? Should I not be using initWithObject or should I be passing it in some other way? I've also tried using autorelease but with the same result.

Upvotes: 0

Views: 151

Answers (2)

Girish Kolari
Girish Kolari

Reputation: 2515

notice - you should not release, since you don't own the object(you are just using a object which is returned from NSArray) else retain this object when you retrieve the object from NSArray and release it later stage.

notice_view - as per you explanation I don't see any issue with releasing, I am assuming you don't have any reference to this object from other part of the code.

Upvotes: 1

Ben Gottlieb
Ben Gottlieb

Reputation: 85522

I'm guessing you'll want to get rid of [selectedNotice release], since there doesn't seem to be a corresponding -retain call in there.

Upvotes: 0

Related Questions