Sam
Sam

Reputation: 829

xcode 4.2 Message from Analyze tool

Little confused about the message from Analyze command in Xcode 4.2. It complains about the instance variable activityView.

enter image description here

Analyze tool complains on [self startRefresh:NULL] line about potential leak of activityView.

  1. activityView is an instance variable, and is synthesized
  2. I am releasing activityView in dealloc()
  3. Per my understanding, when the setter is used (implicitly via self.activityView), the previous value is released, right?

So, I how should I read the warning from the Analyze tool? Or what changes do I need?

Thx.

Upvotes: 0

Views: 317

Answers (1)

Firoze Lafeer
Firoze Lafeer

Reputation: 17143

Assuming the @property has the retain attribute, the setter will retain this new activity view, so you are still responsible for the +1 count from the alloc/init.

So you can do something like this:

self.activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];

Just autorelease the new instance to balance out the alloc/init.

The analyzer isn't warning you about the previous value of activityView. It's warning you about the new instance, which effectively has a +2 retain count after your alloc/init and the @property (retain).

Upvotes: 2

Related Questions