Releasing Object from RSSItem class


First of all, great book! I love it so far.

I have a question regarding to the code on page 423. This code is used to fill up all the cells with the values from your xml file. Near the end of the code, you retained an object of RSSItem and used the title variable of this object to assign the label of the cell. However, as you mentioned earlier, we have to relinquish our ownership of the object if we don’t need it anymore in order to prevent memory leaks. I couldn’t find anywhere in your code where you released this object. I did however try to release it on my own project but it keep giving me crash error whenever I scrolled over the table view to the very end or very start (when you can extend your scroll even though there is no more cells available for viewing). Could you help me out why this could happen?



Im not sure if I am looking at the same code as you. Are you referring to:

RSSITem *item = [[channel items] objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[item title]];

return cell;

If this is the code you are talking about, then there isn’t ever any object retained by our code here. The object that “item” points to is never retained by our code. So it is safe to say that our code never “takes ownership” of the object that “item” points to. That object is still retained by the array which it was stored in. But we never took ownership. Instead, we just created a pointer and pointed it to that objects place in memory.

Its for this reason that if you were to release it, you would get a crash. You are overreleasing that object.

Does that make sense?


Sorry for the confusion on the code that I was referring to. I should have put down the code.

All make sense to me now. Awesome!

it’s really tricky to learn this memory management rules if you have never been exposed to one before. I’m glad that I read your book.

Thanks a lot