2010-11-26 2 views
0

popOver에서 tableView로 구성된 메뉴 만 표시하는 함수를 작성하고 있습니다. 동일한 함수에서 alloc이 하나 뿐인 객체에 대해 다섯 개의 할당이 있습니다.

는 소스 코드 : 카운트가 1

if ([pop isPopoverVisible]) 
    { 
     [pop dismissPopoverAnimated:YES]; 
     [pop release]; 
    } 

    pop = [[UIPopoverController alloc] initWithContentViewController:searchNav]; 

    NSLog(@"Retain Count: %d",[searchNav retainCount]); 
    //At this point retain count is 2 



    [pop presentPopoverFromRect:btnMenu.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
    [pop setPopoverContentSize:CGSizeMake(350,600)]; 

    NSLog(@"Retain Count: %d",[searchNav retainCount]); 
    //At this point retain count is 5!!! 

    [searchNav release]; 

} 

나는 데 문제입니다 유지

-(void)pushSearch:(NSString *)option type:(int)optionType 
{ 
    searchNav = [[iNavigation alloc] initWithNibName:@"iNavigation" bundle:nil] ; 
    //This is the UIViewController with the tableView 

    [searchNav setSearchMode:optionType]; 

    searchNav.view.frame =CGRectMake(0,0,300,600); 

    NSLog(@"Retain Count: %d",[searchNav retainCount]); 

//이 시점에서의 tableview를로드하기 위해 사용 된 메모리가 있다는 것이다 결코 풀려나 지 않았다. 내 앱이 크래시 될 때까지 메모리가 커지고 커집니다.

왜 내가 searchNav에 대한 할당을 하나만 만들고, popOver에 할당 한 후 왜곡 계산은 5입니까?

도와주세요.

답변

4

-retainCount를 사용하지 마십시오.

개체의 절대 보유 개수는 의미가 없습니다.

release과 정확히 같은 회수로 개체를 유지해야합니다. 더 적은 (누수가 마음에 들지 않는 한), 물론, 더 이상 (당신이 충돌을 좋아하지 않는다면).

자세한 내용은 Memory Management Guidelines을 참조하십시오.


보유 횟수가 5 인 것은 관련이 없으며 다양한 프레임 워크의 내부 구현 세부 사항 때문에 가능합니다.

해당 코드에서 searchNav의 메모리 관리가 정확합니다. 당신은 객체를 할당하고 (+1 보유), 결국 그것을 해제합니다 (-1 보유). 따라서 메모리 누수가 다른 곳에서 발생합니다.

소스에서 "빌드 및 분석"을 사용해보세요. 그런 다음 Allocations 도구를 사용하여 시간이 지남에 따라 앱이 커질 때 매달려있는 객체를 살펴보십시오. 어딘가에 잔류가 있습니다. 릴리스와 균형을 유지하지 않은 보유 물.

+1

'[retaincount] 태그가 자동으로'[retaincount-is-evil-stopit-stopit-stop]'으로 리디렉션 될 수 있습니까? – walkytalky

0

UIPopoverController을 출시 하시겠습니까? 아마도 그 객체는 여전히 테이블 뷰를 유지하고있을 것입니다.