0

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?

11684
  • 7,356
  • 12
  • 48
  • 71

2 Answers2

1

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

Community
  • 1
  • 1
Phillip
  • 4,276
  • 7
  • 42
  • 74
  • Thanks for the response! But I think you misread the question. I created the leak on purpose (OK, that's not in there) to test Build and Analyze, and it doesn't show any warning (That IS in the question)! And I know memory management, I'm just redoing the first part of the course because I skipped the homework, I'm doing that now. :) – 11684 Jun 23 '12 at 18:19
  • Ahh sorry! I thought you forgot to dealloc the object! Well i can suggest you to update Xcode and see if the warning is shown in the updated version. – Phillip Jun 23 '12 at 18:24
  • Are you using an older version than Leopard or Lion? Try updating to 3.2.7 – Phillip Jun 23 '12 at 18:51
  • Snow Leopard. Do you think I can run a newer version then 3.2.7 on Snow Leopard? – 11684 Jun 23 '12 at 19:11
  • Sure. If you have Mac App Store, then get the latest Xcode from there! Or check in Apple Developer Center. – Phillip Jun 23 '12 at 19:25
  • I thought that was Lion only? – 11684 Jun 23 '12 at 20:24
  • And I was right: Xcode kan niet op 'Macintosh HD' worden geïnstalleerd, omdat Mac OS X versie 10.7.3 of hoger is vereist. That's Dutch for: XCode can't be installed on 'Macintosh HD', because Mac OS X version 10.7.3 or higher is required. – 11684 Jun 23 '12 at 20:25
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/12951/discussion-between-11684-and-pheel) – 11684 Jun 23 '12 at 20:26
  • @11684 The latest version of Xcode available for Lion is 4.3.3, however since you are running Snow Leopard the maximum supported Xcode version is 4.2 which can be downloaded from developer.apple.com. This is an update I strongly recommend. Xcode 4.2 has a new compiler feature ARC (automatic reference counting) which automatically handles the deallocation of allocated objects for you. – Mick MacCallum Jun 23 '12 at 21:13
  • Wait, developer.apple.com says otherwise. But I'll try installing 4.2 and see if it works. – 11684 Jun 26 '12 at 10:43
  • 4.2 can't be installed on Snow Leopard. Lion is required for that... Thanks nonetheless. – 11684 Jun 26 '12 at 10:51
0

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

logixologist
  • 3,694
  • 4
  • 28
  • 46