2010-05-16 4 views
1

두 번 이상 회전하면 응용 프로그램이 충돌합니다. 처음에는 아이폰 시뮬레이터라고 생각했기 때문에, 아이팟 터치에 앱을로드했고, 회전 수가 줄어들면서 추락했습니다. 내 회전 방법 중 하나에서 메모리 누수가 의심됩니다. 충돌이 발생했다고 생각할 수있는 유일한 곳은 willRotateToInterfaceOrientation:duration:입니다. 추가/확장 된 회전과 관련된 두 가지 방법은 shouldAutorotateToInterfaceOrientation:willRotateToInterfaceOrientation:duration이며 두 단어 만 포함되어 있기 때문에 첫 번째 방법이라고 생각하지 않습니다. return YES;. 여기 내 willRotateToInterfaceOrientation:duration: 메서드가 있으므로 검토하여 가능한 메모리 누수가있는 곳을 확인할 수 있습니다.여러 번 회전하면 내 응용 프로그램이 충돌합니다.

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration 
{ 
UIFont *theFont; 


if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) 
{ 
    theFont = [yearByYear.font fontWithSize:16.0]; 
    yearByYear.font = theFont; 
    [theview setContentSize:CGSizeMake(460.0f, 635.0f)]; 
} 
else 
{ 
    theFont = [yearByYear.font fontWithSize:10.0]; 
    yearByYear.font = theFont; 
    [theview setContentSize:CGSizeMake(300.0f, 460.0f)]; 
} 

[theFont release]; 
} 

yearByYear은 UITextView이고 theview는 UIScrollView이다.

+0

크래시는 일반적으로 누출이 아닌 과도한 객체입니다. 누출은 메모리를 채우는 데 오랜 시간이 걸리며 (홍수가 아닌 한) 먼저 메모리 경고를받습니다. – progrmr

답변

4

theFont을 공개해서는 안됩니다. 당신은 그 물건을 소유하고 있지 않습니다.

당신은 또한 당신이 무슨 일을하는지 간단하게 할 수 있습니다

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration { 

    if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) { 
     yearByYear.font = [yearByYear.font fontWithSize:16.0] 
     [theview setContentSize:CGSizeMake(460.0f, 635.0f)]; 
    } 
    else 
    { 
     yearByYear.font = [yearByYear.font fontWithSize:10.0] 
     [theview setContentSize:CGSizeMake(300.0f, 460.0f)]; 
    } 
} 

완전히 theFont 제거하기.

+1

예. 명시 적으로'alloc '또는'new'또는'copy '폰트가 아니기 때문에 Cocoa 메모리 지침 (링크가 없어도 Google을 사용해야합니다.)에 따르면 매우 명확하게하려면 , 당신은 그것을 풀어서는 안된다. –

+0

yearByYear *는 setter 메서드에서 글꼴을 적절하게 유지하고 해제해야 함을 유의하십시오. 메서드가 합성되고 올바른 속성 특성을 가진 경우이 작업이 완료됩니다. – walkytalky

+0

감사합니다. 많은 사람들, 큰 도움이되었습니다. –