0

I've an UIViewController with a property

@property (nonatomic, retain) NSMutableArray *speakerFetchResults;

Then I set the property in viewWillAppear with

 self.speakerFetchResults = [[[self.speakerViewContext executeFetchRequest:request error:&error] mutableCopy] autorelease];

and want to release it again in the UIViewController's dealloc method with

[self.speakerFetchResults release];

But, if I analyze my file I get on the [self.speakerFetchResults release]; the following warning:

Incorrect decrement of the reference count of an object that is not owned at this point by the caller.

Furthermore (I've testet it out) I get this message on all

[self.anything release]

issues.

So I'm a little bit confused and removing all "self." in this releases or in general cause a lot of errors in the programm. So I think the analyzer is wrong, but I just want to ask you for some help.

What do you think?

Thanks for all your help.

andi1984
  • 676
  • 10
  • 27

1 Answers1

2

You shouldn't call release on the object returned by the getter (the getter may have side effects, custom logic, return autoreleased objects, etc. so you can not assume that [self.speakerFetchResults release] and [speakerFetchResults release] have the same results).

You can simply do:

self.speakerFetchResults = nil; // this releases the old value

Or, in dealloc, where the use of accessors is discouraged:

[speakerFetchResults release];
Community
  • 1
  • 1
albertamg
  • 28,492
  • 6
  • 64
  • 71