1

iPhone開発初心者です。シングルトーンクラスを使用しているアプリケーションを開発しています。シングル トーン クラスのオブジェクトを作成しているときに、コードの分析時にメモリ リークが発生します。「オブジェクトの潜在的なリーク」および「割り当てられたオブジェクトは後で参照されません」というメッセージを出しています。しかし、コードでそのオブジェクトを使用しています。以下は、シングルトーンクラスオブジェクトを作成した私のコードです

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"Inside View");
    self.navigationController.navigationBar.topItem.title = @"Menu List";

    UIImage *image = [UIImage imageNamed:@"Navigation_bar.png"];
    [_bgImage setFrame:CGRectMake(0,-45,320,510)];
    [self.navigationController.navigationBar setBackgroundImage:image
                                              forBarMetrics:UIBarMetricsDefault];
    [self.tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"Tab_bar.png"]];
    [self.navigationItem setHidesBackButton:YES];


    menuTableView.backgroundColor=[UIColor clearColor];
    menuTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

    _hotelMenu=[SharedHotelMenu sharedInstanceMethod];
    _queryFormatter=[[DatabaseQueryFormatter alloc]init];

    _isSearchOn=NO;
    _searchResult=[[NSMutableArray alloc]init];

    _categorySearch.layer.cornerRadius = 19;
    _categorySearch.clipsToBounds = YES;
    _categorySearch.delegate=self;

    UIView *_paddingView=[[UIView alloc] initWithFrame:CGRectMake(0,0,5,10)];
    _categorySearch.leftView=_paddingView;
    _categorySearch.leftViewMode=UITextFieldViewModeAlways;
    [_paddingView release];

    UIView *_paddingRightView=[[UIView alloc] initWithFrame:CGRectMake(0,0,30,10)];
    _categorySearch.rightView=_paddingRightView;
    _categorySearch.rightViewMode=UITextFieldViewModeAlways;
    [_paddingRightView release];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(searchBar)
                                             name:UITextFieldTextDidChangeNotification object:_categorySearch];
}
 }

シングル トーン クラス オブジェクトを _hotelMenu=[SharedHotelMenu sharedInstanceMethod]; として作成しました。

4

1 に答える 1

0

あなたのコードを見る限り、この行はメモリリークを引き起こす可能性があります

menuTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

これは@property(nonatomic, retain) UIView *tableFooterViewそのままで、オブジェクトを保持するため、保持カウントは 2 になります。

これを使って

UIView *footerView = [[UIView alloc] initWithFrame:CGRectZero];
menuTableView.tableFooterView = footerView;
[footerView release];
于 2013-03-21T05:06:42.793 に答える