2011-12-03 1 views
0

MyAppDelegate는 백그라운드 작업을 수행 중이며이 시간 동안 여러보기를 새로 고쳐야하므로 생성 된 각 컨트롤러에 대한 참조가 저장됩니다. AppDelegate에 저장된 컨트롤러의 보유 개수를 처리하는 방법은 무엇입니까?

@interface MyAppDelegate : NSObject <UIApplicationDelegate> { 
    SomethingController *currentSomethingController; 
} 
@property (nonatomic, retain) SomethingController *currentSomethingController; 

컨트롤러 열 수행됩니다

- (void)openSomethingController { 
    MyAppDelegate * app = [[UIApplication sharedApplication] delegate]; 
    app.currentSomethingController = [[SomethingController alloc] init]; 
    [self presentModalViewController:app.currentSomethingController animated:NO]; 
} 

을 그리고 이것은을 닫습니다 컨트롤러 내에서 호출됩니다 MyAppDelegate 컨트롤러에서

- (void)dismissSelf 
{ 
    MyAppDelegate * app = [[UIApplication sharedApplication] delegate]; 
    [app.currentSomethingController release]; 
    app.currentSomethingController = nil; 
[self dismissModalViewControllerAnimated:NO]; 
} 

컨트롤러에 메시지를 보내는 :

- (void)longRunningBackgroundTask { 
    [currentSomethingController performSelectorOnMainThread:@selector(updateData) withObject:nil waitUntilDone:YES]; 
} 

제품 -> 분석을 수행하면 "누출 가능성이 있음"과 "잘못된 감소"경고가 표시됩니다. 이 작업을 수행하거나 내 접근 방식이 정상이라고 가정 할 때 올바른 방법은 무엇입니까? 분석 도구에 해당 줄을 무시하도록 지시하려면 어떻게해야합니까?

답변

0

코드가 괜찮은 것처럼 보이지만 왜 그렇게하고 있습니까? 또한 명시 적 속성에 출시 호출해서는 안, 코드를 읽는 외부인에 혼란을 초래할 수 있습니다, 당신은 단지 메모리 관리는 재산 자체에서 발생하자, 그럼

- (void)openSomethingController { 
    MyAppDelegate * app = [[UIApplication sharedApplication] delegate]; 
    SomethingController *controller=[[SomethingController alloc] init]; 
    app.currentSomethingController = controller; 
    [controller release]; 
    [self presentModalViewController:app.currentSomethingController animated:NO]; 
} 

과 같은 코드를 재 작성해야

- (void)dismissSelf 
{ 
    MyAppDelegate * app = [[UIApplication sharedApplication] delegate]; 
    app.currentSomethingController = nil; 
    [self dismissModalViewControllerAnimated:NO]; 
} 
+0

나는 속성이 단지 객체를 해제하지 않고 유지하고 있다고 생각했기 때문에 혼란스러운 것은 외부 독자 만이 아니었다. 그것을 할 올바른 방법을 지적 해 주셔서 감사합니다! –