tags:

views:

34

answers:

2

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.

A: 

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.

Ben Gottlieb
+1  A: 

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.

Girish Kolari
notice - of course makes sense.k, I tried to just release notice_view which im sure I had tried with the same results but now its working fine -_-Thanks for your reply :)
Rudiger
I figured out what happened while I was stuffing around which has raised another question. If I declare a Dictionary in the Notice_view and copy the passed dictionary into it, if I say dictionary = it fails after the third go, if I say self.dictionary = its Kosher. I came from other languages so excuse me if this is noob or wrong
Rudiger
dictionary = it -> in this case your keeping pointer referring but you are not owning the object(if you have want to own the object dictionary = [it retain])self.dictionary = its - > self.dictionary in this case you are using default setter method defined using 'property'(objective C 2.0) which add a retain count to the object(make it own by the object)
Girish Kolari