Does Instruments' memory leak tool have issues with 'for' loops?
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开发者_如何学JAVA];
}
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).
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?
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.
精彩评论