iphone - Possible optimization to unload the views+controllers which are no longer visible in UIScrollView and PageControl -
I have this page control code which is apple apple sample. Here I have a subview (Controller view) that includes an image view. Now the problem is with memory management all works fine but when I scroll up to 5-10 pages the RAM is filled I release the view + controller Tried to do it, but it did not find any suitable place / route that worked. I want to release those scenes that are not currently visible. (Excluding the current, past and next view)
- (zero) Applications: Definitive launching: (UIApplication *) Application {NSMutableArray * Controller = [[NSMUTABELARRORAL] INST]; For (unsigned i = 0; i & lt; kNumberOfPages; i ++) {[Controllers addObject: [NSNull null]]; } Self.viewControllers = Controller; [Controller release]; ScrollView.pagingEnabled = Yes; ScrollView.contentSize = CGSizeMake (scrollView.frame.size.width * kNumberOf page, scrollView.frame.size.height); ScrollView.showsHorizontalScrollIndicator = No; ScrollView.showsVerticalScrollIndicator = No; ScrollView.scrollsToTop = NO; ScrollView.delegate = self; Page Control NumberOfPages = kNumberOfPages; PageControl.currentPage = 0; [Self-loadsviewview page: 0]; [Self-loadSolarView page: 1]; } - (zero) loadScrollViewWithPage: (int) page {if (page & lt; 0) returns; Return (page & gt; = kNumberOfPages); PageControlExampleViewControl * Controller = [viewControllers objectAtIndex: pg]; If ((NSNull *) Administrator == [NSNull null]) {Controller = [[PageControlExampleViewControl alloc] initWithPageNumber: Page]; [ViewControllersObjectAtIndex: object with page: controller]; [Controller release]; } If (blue == Controller: view.Supervivive) {CGRact frame = scrollview frame; Frame.origin.x = frame.size.width * Page; Frame.origin.y = 0; Controller.view.frame = frame; [Add Add ScrollView: Controller: View]; }} - (zero) scrollviewscroll: (uiscrollview *) sender {if (page control use) {return; } CGFlot pageview = scrollview.fr.image.width; Int page = floor ((scrollView.contentOffset.x - PageWidth / 2) / pagewidth) + 1; PageControl.currentPage = Page; [Self loadscrollview page: pg - 1]; [Self loadsview world page: page]; [Self loadscrollview page: page + 1]; } - (zero) scrollViewDidEndDecelerating: (UIScrollView *) scrollView {pageControlUsed = NO; } - (IBAction) changePage: (ID) sender {int page = pageControl.currentPage; [Self loadscrollview page: pg - 1]; [Self loadsview world page: page]; [Self loadscrollview page: page + 1]; CGRect frame = scrollView.frame; Frame.origin.x = frame.size.width * Page; Frame.origin.y = 0; [ScrollView scrollRectToVisible: animated frame: yes]; Pagewise use = yes; }
I tried the code of Deepmist for several hours but it did I got memory warnings and scrolled every 25-30 pages in my app (I am using large images in pages). In the tool I have seen a huge amount of memory: Even if unnecessary ideas were removed from time to time with supervision and relative view, the controllers were replaced with NSNULUS, the device showed that 4- The crawl increases on every page of 5 MB!
By searching the web I found that this is a common problem if you also have this problem, then you should try the following check:
1) In each view, the image Be sure to use the InternetNumber of ImageName instead. Name the cache images as documented images and increase the memory size.
2) In the lampmaster code, after that:
[controller.view removeFromSuperview]; You also have to set the scene to close:
controller.view = zero; This trick solved memory consumption, which is now stable for only three ideas (to avoid current, current -1 and current + 1 shine in page code).
Hope it helps!
Comments
Post a Comment