0

I am getting exception on few of my ViewControllers when I go through browsing the application.

The exception is occurring in viewdidunload, I think this is due to memory warning. The following line gets an exception which are the IBOulet objects.

self.LabelDistance = nil;
self.distanceSlider = nil;

Please help. Thanks

iosdevnyc
  • 1,873
  • 5
  • 25
  • 48

2 Answers2

1

Why would you want to set this to nil?

If it's a @property (retain) UILabel * labelDistance; (and synthesized), then just release it in dealloc. Or do you fiddle with that ivar around?

One note: your variable and property should begin with a lower letter "l".

Eiko
  • 25,601
  • 15
  • 56
  • 71
-1

Try:

[self.labelDistance release];
[self.distanceSlider release];

instead. Also, you shouldn't be releasing ivars in viewDidUnload, release them in dealloc. If the problem persists, run the static analyzer (Build menu >> Build and Analyze), it is generally good at finding memory related issues.

indragie
  • 18,002
  • 16
  • 95
  • 164
  • You should release IBOutlets in viewDidUnload. Because when the view is loaded again it will set them. – rickharrison Jun 21 '10 at 00:43
  • @rickharrison - Although if they're properties constructed with the `retain` setter semantic, they'll be released in the synthesized setter when the new value is set. At which point, I think you'd run the risk of over-releasing them, if you did it in viewDidUnload too. – Dan Ray Jun 22 '10 at 12:50
  • @Dan Ray - Well if you do self.iboutlet = nil in viewDidUnload than the memory will be reclaimed by the system. That also allows a safe call of resetting the outlet in viewDidLoad again. – rickharrison Jun 22 '10 at 17:16
  • @rickharrison: I'm saying, I think that shouldn't be necessary, as long as the properties are of the "retain" style. Just assigning to that property a second time (as long as you use the @synthesized setter, possibly via dot notation) will release the previous content before it assigns. – Dan Ray Jun 23 '10 at 12:02
  • voted down because you should not call [self.xxx release]. See http://stackoverflow.com/a/5737438/119321 – Agathe Dec 30 '11 at 23:39