0

Objective-C 프로그래밍에 익숙하며 일반적인 메모리 문제가 있습니다. 내비게이션 컨트롤러를 기반으로하는 앱을 수행해야하며 푸시보기 컨트롤러를 사용하여 몇 개의보기를 전달할 때 100 개의 이미지 애니메이션을로드해야합니다. 시뮬레이터에서는 잘 작동하지만 전화에서는 그렇지 않습니다. 다른 애니메이션을 연 다음 닫습니다. 그것을 피하기 위해 호를 사용하고 있지만 작동하지 않는 것 같습니다. 또한 arc를 비활성화하고 UIImageView를 수동으로 릴리스하려고 시도했지만 빠르게 충돌합니다. 보기 중 하나의 예는 다음과 같습니다.아크를 이용한 메모리 문제

//.h 
@interface Gegant_nou : UIViewController { 

IBOutlet UIImageView *ImageViewGegant; 
} 

@property (nonatomic, strong) UIImageView* ImageViewGegant; 

//.m 

- (void)viewDidLoad { 

    [super viewDidLoad]; 


    UIBarButtonItem *rigthButton = [[UIBarButtonItem alloc] initWithTitle:@"Detalls" style:UIBarButtonItemStyleBordered target:self action:@selector(canviarDetalls)]; 
    self.navigationItem.rightBarButtonItem = rigthButton; 
    [rigthButton release]; 


    ImageViewGegant.animationImages [email protected] 
     [[UIImage imageNamed:@"0001.png"], 
     [UIImage imageNamed:@"0002.png"], 
     . load all the images 
     . 
     [UIImage imageNamed:@"0099.png"], 
     [UIImage imageNamed:@"0100.png"]]; 

    ImageViewGegant.animationDuration = 4; 
    ImageViewGegant.animationRepeatCount = 0; 
    [ImageViewGegant startAnimating]; 
    [self.view addSubview:ImageViewGegant]; 

    self.title = @"Gegant nou"; 

    [ImageViewGegant release]; 

} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ 

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)didReceiveMemoryWarning{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 

} 

- (void)viewDidUnload{ 
    [super viewDidUnload]; 
    [ImageViewGegant release]; 
} 

어떤 아이디어가 발생합니까? 도와 주셔서 감사합니다!

+0

1. 어떤 줄이 예외를 던집니까? 2.'-viewDidUnload'는 iOS6에서 사용하지 않는 것이 좋습니다 (절대로 호출되지 않습니다). 3. 왜 루프를 사용하여 이미지 배열을 초기화하지 않습니까? – holex

+0

ImageNamed를 사용하여 vs initwtihcontentsoffile을로드 할 때 메모리 사용에 대한 몇 가지 논쟁이 있습니다. 다른 옵션에 대한 좋은 정보는이 게시물을 참조하십시오. http://stackoverflow.com/questions/6566827/iphone-ios-how-to-load-a-lot-of-image-in-many-folder-and-show -in-a-table-view –

+0

@holex viewDidUnload 대신 무엇을 사용해야합니까? 탈락? – joan2404

답변

0

문제가 해결되었습니다. UIImageNamed를 사용하여 애니메이션을로드하는 중이 었는데 ARC를 사용했지만 UIImageNamed는 이미지를로드하지만 놓지 않았으므로 모든 프레임을로드하고 메모리를 매우 빠르게 채 웁니다. 지금 나는 그 기억 문제가 없다. 모두에게 감사드립니다!

1

문제가있는 곳에 대한 자세한 정보를 제공하기 위해 일부 crashlog 또는 스택 추적을 제공하면 도움이 될 것입니다.

메모리 관련 문제가 전혀 발생하지 않았습니까? ARC를 사용하고 있기 때문에 코드베이스에서 ARC를 사용하지 않는 부분이 없거나 ARC를 사용하더라도 CoreGraphics 등의 c 라이브러리를 사용하는 경우 여전히 유지/해제해야합니다.

만약 당신이 EXT_BAD_ACCESS 충돌과 관련하여 메모리 문제가 발생하면 제품 -> 편집 스키마 -> 진단 및 "좀비 오브젝트 사용"순으로 앱에서 좀비를 활성화 할 수 있습니다. 이렇게하면 문제의 원인이되는 개체에 대한 자세한 정보를 얻을 수 있습니다.

전혀 다른 주제로 모든 인스턴스 변수를 camelcase로 작성하는 것이 좋습니다. 읽을 때 혼란 스럽지만 대부분의 개발자는 "ImageViewGegant"가 클래스의 이름이라고 가정합니다.

+0

EXC_BAD_ACCESS [여기 캡처보기] (https://dl.dropbox.com/u/2720540/Captura%20de%20pantalla%202012-09-29%20a%20les%)라고 말하면서 메모리 문제가 있습니다. 2021.14.21.png). coregraphics 라이브러리를 사용하고 있습니다. 모두에게 감사드립니다. – joan2404