Uiview IBOutlet没有释放

Uiview IBOutlet没有释放,uiview,release,retain,iboutlet,Uiview,Release,Retain,Iboutlet,我有这个问题。我有两个IBO门店和as酒店,我将保留它们 @interface MCNavigationController : UIViewController @property (retain, nonatomic) IBOutlet UIView *contentView; @property (retain, nonatomic) IBOutlet MCNavBar *navBar; @end 问题是,在dealloc中,在我完成所有发布之后,contentView和navBa

我有这个问题。我有两个IBO门店和as酒店,我将保留它们

@interface MCNavigationController : UIViewController 

@property (retain, nonatomic) IBOutlet UIView *contentView;
@property (retain, nonatomic) IBOutlet MCNavBar *navBar;

@end
问题是,在dealloc中,在我完成所有发布之后,contentView和navBar仍然没有被释放

- (void)dealloc
{
    [contentView release];
    NSLog(@"%@",contentView.superview);
    [navBar release];
    NSLog(@"%@",navBar.superview);
    NSLog(@"%@",self.view);

    [super dealloc];
    NSLog(@"%@",navBar.superview);
    NSLog(@"%@",contentView.superview);
    NSLog(@"%@",self.view);
}

在日志中,我得到的是:

2012-08-21 14:48:05.646 ShopRite[4250:12503] <UIView: 0x66b77d0; frame = (0 0; 320 416); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x66b7800>>
2012-08-21 14:48:05.649 ShopRite[4250:12503] <UIView: 0x66b77d0; frame = (0 0; 320 416); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x66b7800>>
2012-08-21 14:48:05.650 ShopRite[4250:12503] <UIView: 0x66b77d0; frame = (0 0; 320 416); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x66b7800>>
2012-08-21 14:48:05.650 ShopRite[4250:12503] <UIView: 0x66b77d0; frame = (0 0; 320 416); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x66b7800>>
2012-08-21 14:48:05.651 ShopRite[4250:12503] <UIView: 0x66b77d0; frame = (0 0; 320 416); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x66b7800>>
2012-08-21 14:48:13.726 ShopRite[4250:12503] *** -[MCNavigationController view]: message sent to deallocated instance 0x66b5f20
2012-08-2114:48:05.646 ShopRite[4250:12503]
2012-08-21 14:48:05.649 ShopRite[4250:12503]
2012-08-21 14:48:05.650 ShopRite[4250:12503]
2012-08-21 14:48:05.650 ShopRite[4250:12503]
ShopRite[4250:12503]
2012-08-21 14:48:13.726 ShopRite[4250:12503]***-[MCNavigationController视图]:发送到解除分配实例0x66b5f20的消息
但我应该会收到一条“发送到navBar和contentView的解除分配实例的消息,就像我为self.view设置的et一样。我很确定我不会在其他任何地方保留它们,也不会将它们添加到其他视图中。”


如果您有任何建议,我们将不胜感激。

我假设您正在使用xib

如果您使用的是xib,那么当它从superview或从窗口中删除时,它将被释放

当我们使用IBOutlet时,我们不需要进行发布

在我完成了所有的发布之后,contentView和navBar仍然不可用 解除分配

- (void)dealloc
{
    [contentView release];
    NSLog(@"%@",contentView.superview);
    [navBar release];
    NSLog(@"%@",navBar.superview);
    NSLog(@"%@",self.view);

    [super dealloc];
    NSLog(@"%@",navBar.superview);
    NSLog(@"%@",contentView.superview);
    NSLog(@"%@",self.view);
这些观点可以通过多种方式保留:

  • 这些视图可能是控制器视图的子视图(因此由控制器视图保留)。并且控制器视图将仅在
    UIViewController
    dealloc
    中发布,这发生在
    dealloc
    的末尾,因此它不会发生在您记录它的地方
  • 由于您正在加载带有xib的视图控制器,因此视图控制器在加载时会保留xib及其所有对象。因此,这将再次在
    UIViewController
    dealloc
    中释放,这将发生在
    dealloc
    的末尾
  • 如果有人保留并自动删除对象,它们仍然可以被自动删除池保留。(许多代码保留并自动删除对象,因为这样做从来都没有错。)因此,对象解除分配的确切时间并不总是可预测的。只需担心在您的端正确地进行内存管理,而不用担心

  • 我使用的是nib,调用了ViewController dealloc方法,因此它的视图将从superview中删除,但这两个插座未正确释放。如果属性是使用retain创建的,则需要在dealloc中释放它。