Question

I am currently doing the CS193P lessons via iTunesU and the teacher mentioned the Build and Analyze option several times. He said that it was a nice tool and fun to play with.
So I tried, and noticed that it doesn't work, or that I don't understand how it should work (I think the last option).
I have a few memory leaks, and it is not warning me at all! I saw online that a blue thing should appear telling me it is a leak, but I don't see anything although I'm doing NSDictionary *dict = [[NSDictionary alloc] init];.

How is it supposed to work? From what I read on the internet I thought it should signal potential leaks. What am I doing wrong?

I'm using XCode 3.2.5.

Thanks.

Update:

This is a kind of bug, I think.
When I declare this in the interface like NSDictionary *dict; and initialize it (but nowhere deallocating it) it says nothing.

When I declare and initialize it in - (void) init and don't release it in there like:

- (void) init {
    if(self = [super init])
        NSDictionary *dict = [[NSDictionary alloc] init];
    return self;
}

It does signal a leak. Why? Is this because of my settings? Is this a bug? If it is a bug, where and how should I report it?

Was it helpful?

Solution

It's giving you a warning because you're not deallocating it.

-(void)dealloc{
   [super dealloc]; 
   [dict dealloc];
}

It's not warning you because you should be able to release the objects as soon as you create them, and the analyzer goal is to alert you on possible leaks in your code.

You can either use autorelease, or you dealloc the object you create manually.

P.S., little curiosity: why are you using Xcode 3.2.5?

Don't know exactly if that version can, but in the latest versions of Xcode, when you run that tool, you are able to see WHAT object you are deallocating with the means of some arrows with explanation, something like

OTHER TIPS

I just found out that a reboot and restart of Xcode will bring it back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top