【发布时间】:2013-03-01 11:07:26
【问题描述】:
似乎 UIPageViewController 永远持有初始内容视图控制器。 例如:
DataViewController *startingViewController = [self.modelController viewControllerAtIndex:0 storyboard:self.storyboard];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];
self.pageViewController.dataSource = self.modelController;
startingViewController 在释放 pageViewController 本身之前永远不会释放。
要重现此错误,只需使用基于页面的应用程序模板在 XCode 中创建一个新项目。并在DataViewController.m中添加3行代码
@property NSInteger debugIndex; // file scope
NSLog(@"DataViewController[%d] created", self.debugIndex); // in viewDidLoad
NSLog(@"DataViewController[%d] dealloc", self.debugIndex); // in dealloc
当你在垂直方向滚动演示应用程序时,你会得到这样的日志:
DataViewController[0] created
DataViewController[1] created
DataViewController[2] created
DataViewController[1] dealloc
DataViewController[3] created
DataViewController[2] dealloc
DataViewController[4] created
DataViewController[3] dealloc
DataViewController[5] created
DataViewController[4] dealloc
DataViewController[6] created
DataViewController[5] dealloc
DataViewController[0] 永远不会被释放。
对此有什么想法吗? 谢谢!
【问题讨论】:
-
您有没有找到 ARC 的解决方案?
标签: memory-leaks uipageviewcontroller