0

我的根视图控制器的释放方法被调用了38次,但我没有调用释放,为什么会发生?

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [_viewController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
    } else {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

@interface ViewController ()

@end

@implementation ViewController

-(oneway void)release
{
    NSLog(@"release called");
    [super release];
}

@end

输出

2013-04-09 19:47:36.060 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.063 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.064 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.065 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.065 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.066 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.067 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.068 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.072 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.073 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.074 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.075 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.077 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.080 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.081 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.081 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.082 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.108 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.110 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.111 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.112 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.134 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.144 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.158 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.161 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.170 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.180 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.182 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.193 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.197 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.198 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.199 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.202 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.208 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.208 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.218 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.220 TesteRelease[44985:c07] release called
2013-04-09 19:47:36.220 TesteRelease[44985:c07] release called

我没有使用ARC。

4

2 回答 2

3

框架的一部分在他们认为合适的时候保留和释放(或自动释放)对象。这是鼓励您不要尝试精确跟踪保留计数的众多原因之一——您不需要知道所有这些保留和释放正在发生,因为它们与您无关。

于 2013-04-09T22:59:48.347 回答
1

最有可能的是,您的视图控制器在通过系统库传递时被添加到自动释放池中。但只要您确信您的代码正确地管理视图控制器,您就应该将其视为背景噪音而忽略。

于 2013-04-09T22:59:20.247 回答