I have this property called mySegmented, declared like this
.h
@property (retain) UISegmentedControl *mySegmented;
.m
@synthesize mySegmented = _mySegmented;
then, it was created like this:
self.mySegmented = [self createSegmented];
// createSegmented creates an autoreleased segmented control
My app has 3 different segmented controls. Just one appears at a given time.
At some point of my app, I have to hide one particular segmented control, so, what I do is to build an array of all segmented controls and iterate… this is inside a block.
[UIView animateWithDuration:0.8
animations:^{
NSArray *list = [NSArray arrayWithObjects:
self.mySegmented1,
self.mySegmented2,
self.mySegmented3,
nil];
for (UISegmentedControl *oneSeg in list) {
[oneSeg setAlpha:0.0f];
}
}];
what happens is: after some time, the app crashes while trying to build this array. I suppose one of the segmented controls is deallocated somehow. No deallocation that I can see in code.
My question is: this array being created is autoreleased. What happens when the block finishes the animation? is a release sent to each member of the array?
If I retain the segmented control after creating it, Xcode complains it will leak.
any clues?
thanks.
Please retain like you tried, but make sure to release them in the
deallocmethod, Xcode should not complain that way.Your array is also autoreleased inside the block but that’s fine, the array doesn’t own the references inside of it, the real problem is the segmented controls not being retained by your view controller.
Let me know how it goes.