tags:

views:

38

answers:

2

Hey Guys,

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

+1  A: 

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
+1  A: 

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.

macatomy
You should release IBOutlets in viewDidUnload. Because when the view is loaded again it will set them.
rickharrison
Ah good point, I didn't realize they were IBOutlets.
macatomy
@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
@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
@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