1

Im new to X-code and have been searching everywhere and trying "everything" with no luck. If you can help me I will sing you a song :)

Im making an IPad app that uses a lot of memory. The size of the project is about 100mb (many images) but the Activity monitor shows that Im using up to 140mb "real memory" after Ive switched between all the views (xib-files) :(

My memory footprint increases every time I switch between views (xib files). ARC is enabled so I can't release the previous view from memory. I have 10 pages (xib files) to switch between.

Im using this code to switch between the xib-files:

viewController2 *view2 = [[viewController2 alloc] initWithNibName:@"viewController2" bundle:nil];
view2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:view2 animated:YES];

When I switch back or to the next view, I use the same kind of code.

Ive tried using [self dismissModalViewControllerAnimated:NO];, [self.view removeFromSuperview];, self.view = nil; but the memory keeps increasing.

As I understand it the views are stacked on top of each other causing the memory to increase.

How can I switch to the next view (xib-file) and at the same time kill the memory usage of my first view?

This problem has made me pull all my hair out :(

taskinoor
  • 45,586
  • 12
  • 116
  • 142

1 Answers1

1

I have an app with 40 some different full screen view controllers. It's a kind of interactive slide show where each slide has some sort of interaction. I've setup this app with a master view controller which controls which individual view controller is presented at which time. I transition from one view controller to the next by adding the new view controller as a child view controller and the new view controller's view as a subview of the master view controller's view:

[self addChildViewController:newView];
[self.view addSubview:newView.view];

self being the master view controller. Then I use UIView's transitionWithView:duration:options:animations:completion: class method to show the new view. In the completion block the view and view controller are removed, allowing ARC to dispose of that memory (as long as there are no other strong references to these objects):

void (^theCompletion)(BOOL) = ^(BOOL finished) { 
    [oldView.view removeFromSuperview]; 
    [oldView removeFromParentViewController]; 
};
Mr. Berna
  • 10,525
  • 1
  • 39
  • 42