I use xcode 4.4 with ARC on. I have dynamically created UIViews in the ViewController.m:
UIView* myviews[10];
Then in the - (void)viewDidLoad function i fill each of it with pictures i need
myviews[viewIndex] = [[UIView alloc]initWithFrame:myrec];
UIImage *testImg;
UIImageView * testImgView = [[UIImageView alloc]init];
testImg = [UIImage imageNamed:[NSString stringWithFormat:@"imgarray%d.png", viewIndex];
[testImgView setImage:testImg];
[myviews[viewIndex] addsubView:testImgView];
viewindex++;
So all seems to be fine, when i want to jump from one view to another i do with two buttons next:
[self.view addSubview:views[viewIndex]];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0f];
[animation setType:@"rippleEffect"];
[animation setSubtype:kCATransitionFromTop];
//[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.layer addAnimation:animation forKey:@"transitionViewAnimation"];
Nothing seems to be bad, but the memory consumption grows with huge speed when i switch between views.. and then i get low memory warning or sometimes application will just crash.
I have tried to use UIViewController array and was switching between the controllers: nothing changes, the memory low warning is what i end up with..
Maybe i need to clean the memory somehow? But how? ARC does not allow to use release and so on..
last what i have tried (sorry, maybe not very professional) before to add new subview is this
NSArray *viewsToRemove = [self.view subviews];
for (UIView *views in viewsToRemove) {
[views removeFromSuperview];
}
But this does not help either.
EDIT: I need to clarify one thing: i need each UIView during the application execution, this means i can't release it before the application exit.
EDIT2: code is edited to look more alike the real code.