Objective-c发布了这么多次

时间:2013-04-09 22:56:00

标签: objective-c release

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

@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

outpout

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。

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

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