0

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.

Sam
  • 827
  • 4
  • 9
  • 21

1 Answers1

2

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).

Firoze Lafeer
  • 17,133
  • 4
  • 54
  • 48