kanai
kanai

Reputation: 33

Instruments not detecting a memory leak in Xcode

I have been puzzling over this for days now. I'm still trying to wrap my head around memory management in objective-c.

Here is my snippet (condensed for clarity):

- (void)performOperation:(NSString *)operation
{
    if ([@"+" isEqual:operation]) 
    {
        waitingOperation = operation;
    }
    else if ([@"C" isEqual:operation])
    {
        waitingOperation = nil;
    }

}

waitingOperation is merely a local private NSString (no @property, no @synthesize, no getters/setters).

Shouldn't I be leaking memory when I assign waitingOperation to nil when it's currently pointing to an NSString on the heap? My call to this method is in an ios app that is passing NSString from UILabel display.text. I've been profiling this code with Instruments and I never see any leaks. I would really appreciate some clarity on this. Thanks in advance.

Upvotes: 2

Views: 583

Answers (1)

walkytalky
walkytalky

Reputation: 9543

You haven't laid a claim of ownership on waitingOperation by calling retain, so you have no responsibility to release.

This may lay you open to problems at some point if the string is released elsewhere (by disposing of the UILabel for example), in which case you'll be left with a dangling pointer. But you aren't leaking anything here.

Upvotes: 1

Related Questions