views:

67

answers:

2

Running my app in the simulator under Instruments to check for memory leaks, it seems to be indicating a leak in this block of code:

for (NSDictionary *messageDict in messageDataArray)
{
    message = [[Message alloc] init];
    ... set some properties on the 'message' object

    [messages addObject:message];
    [message release];
}

Obviously, in this loop, I'm alloc/init'ing an object, but releasing it when I'm finished with it. Wondering if this is just a symptom of how Instruments sees the activity within that loop, or if I'm losing my mind (or doing something else completely wrong).

+2  A: 

You're stashing each message you create into messages... are you sure that that doesn't eventually leak (and thus the things in it)? Or perhaps memory being leaking in your initializer, or property accessors?

Sixten Otto
"messages" gets sent back to this class's delegate and released by this class. It would appear to be well-managed by that class (the accessor for it releases the old and retains the new, and releases it in dealloc).If messages itself, or an owning class of messages, were being leaked, I would see an MSNutableArray showing up as a leak, would I not?
ChrisW
The devil is in the details. Within that delegate class (a UITableViewController subclass), it creates some custom UITableViewCell subclass objects which weren't releasing the 'message' object they were given.Appreciate the feedback, though, that's what got me digging!
ChrisW
+1  A: 

Leaks only shows you where leaked memory was allocated...

Think about what a leak means. It means that somewhere, you should have had a line of code that released something, but you do not have that line of code. Leaks cannot show you code that does not exist!

So what is means, is that one of the message objects in there is being retained somewhere else and never let go of - OR that the entire messages array was leaked somewhere, but then that array allocation would also show in leaks.

Kendall Helmstetter Gelner