When you created your UIViewController
s you never released your own ownership of it, so until you release it yourself, it will never go away. The problem is that nothing else owns the UIViewController
s, so if you used autorelease
, they would be deallocated right away.
My solution would be to create an NSMutableArray
and add them to the array before calling release on them. Then, when you want to release all of your UIViewController
s, remove them from the array. NSMutableArray
retains ownership of objects you add to it and releases ownership upon removal or deallocation. Something like this:
-(id) init {
subViewControllers = [NSMutableArray new];
}
...
-(void)AddOneButton:(NSInteger)myButtonTag {
...
if(categoryType==1) {
MultiChoiceThumbViewControllerobj = [[MultiChoiceThumbViewController alloc] initWithPageNumber:myButtonTag+1];
MultiChoiceThumbViewControllerobj.view.frame=frame2;
MultiChoiceThumbViewControllerobj.lblCounter.text=[NSString stringWithFormat:@"%d of %d",myButtonTag+1,flashCardsId.count];
MultiChoiceThumbViewControllerobj.lblQuestion.text=[flashCardText objectAtIndex:myButtonTag];
[myScrollView addSubview:MultiChoiceThumbViewControllerobj.view];
[subViewControllers addObjet:MultiChoiceThumbViewControllerobj];
[MultiChoiceThumbViewControllerobj release];
}
[myScrollView addSubview:Button];
}
...
- (void) removeSuperviews {
for(UIView *subview in [myScrollView subviews]) {
[subview removeFromSuperview];
NSLog(@"Subviews Count=%d",myScrollView.subviews.count);
}
[subViewControllers removeAllObjects];
}
Ed Marty
2009-08-29 14:01:17