2011-08-02 4 views
2

프로젝트 Xcode를 분석하는 동안 사용자 정의 UIBarButtonItem에서 posibe 누출 알림이 제공되었습니다. 누수가 수정되었지만 두 번째로 뷰를로드하는 동안 [super dealloc]은 EXC_BAD_ACCESS 오류를 표시합니다. UIBarButtonItem에서 오토 릴리즈를 제거super dealloc EXC_BAD_ACCESS 오류

(그래서 경고를 반환) : 화면을 다시로드하는 동안

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease]; 

더 문제를 제공하지 않습니다.

사용자 정의 UIBarButtonItem 및 할당 해제 코드 : NSZombieEnabled와

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // create a toolbar to have the buttons at the right side of the navigationBar 
    UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 44.01)]; 
    toolbar.tintColor = [UIColor clearColor]; 
    [toolbar setTranslucent:YES]; 

    // create the array to hold the buttons, which then gets added to the toolbar 
    NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4]; 


    // Create a comments button 
    propertiesButton = [[UIBarButtonItem alloc] 
         initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(properties)]; 
    [buttons addObject:propertiesButton]; 
    [propertiesButton release]; 

    // Create a comments button 
    commentaryButton = [[UIBarButtonItem alloc] 
         initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(comments)]; 
    [buttons addObject:commentaryButton]; 
    [commentaryButton release]; 

    // create a versions button 
    versionsButton = [[UIBarButtonItem alloc] 
         initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(versions)]; 
    [buttons addObject:versionsButton]; 
    [versionsButton release]; 

    // create a save button 
    downloadButton = [[UIBarButtonItem alloc] 
         initWithBarButtonSystemItem:UIBarButtonSystemItemOrganize target:nil action:@selector(download)]; 
    [buttons addObject:downloadButton]; 
    [downloadButton release]; 

    // stick the buttons in the toolbar 
    [toolbar setItems:buttons animated:NO]; 

    [buttons release]; 

    // and put the toolbar in the nav bar 
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease]; 
    [toolbar release]; 
} 

- (void)dealloc 
{ 
    [popOverController release]; 
    [propertiesButton release]; 
    [downloadButton release]; 
    [versionsButton release]; 
    [commentaryButton release]; 
    [webView release]; 
    [super dealloc]; 
} 

은 내가

'2011-08-01 10:30:36.571 ProjectName[100:707] *** -[UIBarButtonItem release]: message sent to deallocated instance 0x1fb330' 

우리는 문제를 해결하는 방법을 잘하지 않습니다 얻을.

미리 감사드립니다.

답변

4

propertiesButton, downloadButton, versionsButton, commentaryButton을 두 번 릴리스하고 있습니다. 처음으로 viewDidLoad에서 다시 dealloc에 있습니다.

이미 viewDidLoad으로 출시 했으므로 dealloc에서 해당 버전을 출시 할 필요가 없습니다.

+0

매우 감사드립니다! dealloc 메서드에 속성을 추가 할 때 만드는 루틴입니다. 그러나 다른 물체를 통해 물체를 통과 할 때도 물체를 방출합니다. xcode가 문제가 [super dealloc]에 있다고 말하는 것은 아직도 이상합니다. 감사합니다 .1 – Justin

+0

Welcome! Juzzz! – EmptyStack

0

당신이 배열에 추가 한 후 이미 UIBarButtonItem 년대를 해제 - 그래서 당신 가의 dealloc 메서드에서 다시 해제하지 않아야합니다 - 앱 충돌 이미 버튼을 해제하기 위해 메시지를 보내는 그 여분의 릴리스 호출 결과 및 확인

0

내가보기에, 당신은 두 번 버튼을 공개하고 있습니다. viewDidLoad() 함수에서 처음으로 dealloc 함수에서 마지막으로.