似乎 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;
在pageViewController 本身释放之前,startingViewController 永远不会被释放。
要重现此错误,只需使用基于页面的应用程序模板在 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]永远不会被释放。
有什么想法吗?谢谢!