我无法弄清楚为什么在这种情况下不会销毁/释放FirsViewController.
我的AppDelegate.m - FirstViewController被推入堆栈
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
self.navigationController = [[UINavigationController alloc]init];
self.FirstViewController = [[FirstViewController alloc]
initWithNibName:@"FirstViewController"
bundle:[NSBundle mainBundle]];
[self.navigationController FirstViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
FirstViewController.m
self.SecondViewController = [[SecondViewController alloc]
initWithNibName:@"SecondViewController"
bundle:[NSBundle mainBundle]];
self.SecondViewController.totalNumberOfPlayers = self.selectedRow;
[self.navigationController pushFadeViewController:self.SecondViewController];
[self.view removeFromSuperview];
-(void)dealloc
{
[SecondViewController release];
NSLog(@"SecondViewController released");
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序并从第一个视图控制器切换到第二个视图控制器时,控制台中没有NSLog输入.这让我觉得第一个视图控制器没有被破坏,并且没有释放它的内存.
似乎[self.view removeFromSuperview]在这种情况下效果不佳.
我的问题是如何释放/销毁FirstController?它将永远不会在应用程序的其余部分使用.
这是我的代码
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *str = [[NSString alloc]initWithString:@"This is string object"];
NSLog(@"%lu", [str retainCount]);
[pool drain];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我期望输出为1因为它是新创建的对象,但结果是1152921504606846.这里有什么问题?