1

I have this retained property declared like this:

@property (nonatomic, retain) NSMutableDictionary *codes;

then I synthesize this:

@synthesize codes;

I use the property like this:

self.codes = [NSMutableDictionary dictionary];

Then, I forget to say [codes release]; in my dealloc.

When I run Analyzer in XCode 4.3.2, this is not shown as an issue. My base SDK is iOS 5.1 and my compiler is Apple LLVM compiler 3.1

Why doesn't analyzer pick this up?

aslı
  • 8,740
  • 10
  • 59
  • 80
  • are you using ARC? it's probably ARC release it for you. – Andy Jun 08 '12 at 07:36
  • Why you forgot? Just don't. Tip put your dealloc immediately under the @synthesize and when you write a new prop with copy or retain just add it in to dealloc. Follow this rule and you never will have this prob. – Alex Terente Jun 08 '12 at 07:42
  • @EtileVed no, this was an old project and no configuration is changed to use ARC. – aslı Jun 08 '12 at 07:54
  • @AlexTerente I didn't forget it actually, I was reviewing someone else's code and I saw this. Then I wondered why this doesn't show up in the analyzer. Thanks though :] – aslı Jun 08 '12 at 07:54

2 Answers2

1

I imagine it's because the analyzer can't reliably detect retain/release issues across method/library boundaries.

You could conceivably pass ownership of your codes array to some external method or library which will release it later on for you. This would be bad practice because the receiving method should just retain it if it needs it, but I've seen this kind of thing done by inexperienced developers.

So you might see this in your class somewhere:

[SomeAPI takeThisArrayAndReleaseItLater:codes];

The analyzer has no way to know that your class is no longer responsible for releasing the array. To give you a warning would be incorrect, despite the fact that you are not following good memory management practices.

The analyzer is very good at only warning on real issues. I don't think I've ever seen a false-positive outside of betas builds, which is a good thing.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
0

If you havent change anything from the configuration, whenver you target ios5+ you will automatically be using ARC (Automatic Reference Counting) which doesnt require you to release or retain.

The most disruptive change in iOS 5 is the addition of Automatic Reference Counting, or ARC for short. ARC is a feature of the new LLVM 3.0 compiler and it completely does away with the manual memory management that all iOS developers love to hate.

This is a post by iOS Tutorial Team member Matthijs Hollemans, an experienced iOS developer and designer.

Pochi
  • 13,391
  • 3
  • 64
  • 104
  • Not only does it not require you to, it *forbids* you to. – borrrden Jun 08 '12 at 07:49
  • But the analyzer shows an issue if I alloc/init an array inside a method and then don't release it there. What's the reason of this difference? – aslı Jun 08 '12 at 07:59
  • When using ARC, the analyzer will not issue warnings on these kinds of things. So clearly the OP is not using ARC. – Mike Weller Jun 08 '12 at 07:59
  • @borrrden no, you can disable the use of arc if you want. – Pochi Jun 08 '12 at 08:04
  • @MikeWeller well the question doesnt say anything about a warning, so its not so clear. btw what is op? – Pochi Jun 08 '12 at 08:07
  • OP means "Original Poster". The problem is that the analyzer will not show its blue warnings/issues in the situation the OP describes. – Mike Weller Jun 08 '12 at 08:11
  • @MikeWeller well if you check the time when he posted the "no, this was an old project and no configuration is changed to use ARC" you can see how he said it after I answered, there is no need to be so aggressive about an answer when not all the information is known. – Pochi Jun 08 '12 at 08:18
  • Sorry if you interpreted agression in my comment(s), I didn't mean for that! – Mike Weller Jun 08 '12 at 08:21
  • @LuisOscar If you disable it, then you are no longer bound by its rules of course. – borrrden Jun 08 '12 at 08:58