2012-06-01 1 views
0

.H :iOS : 누수가 있습니까?

#import <UIKit/UIKit.h> 
#import "Todo.h" 
@interface TodoCostApplyViewController : UIViewController 

{ 
    NSThread* headViewThread; 
    NSThread* tableViewThread; 
} 
@property (nonatomic, retain) NSThread* headViewThread; 
@property (nonatomic, retain) NSThread* tableViewThread; 
@end 

하는 .m :

@interface TodoCostApplyViewController() 
@end 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    headViewThread = [[NSThread alloc] initWithTarget:self 
              selector:@selector(drawHeadView) 
               object:nil]; 
    [headViewThread start]; 
    tableViewThread = [[NSThread alloc] initWithTarget:self 
             selector:@selector(drawTableView) 
              object:nil]; 
    [tableViewThread start]; 
} 

- (void)dealloc 
{ 
    [tableViewThread release]; 
    [headViewThread release]; 
} 

tableViewThread 및 headViewThread에 대한 메모리 누수가 있습니까? 누수가있는 경우이 문제를 어떻게 처리해야합니까? 미리 감사드립니다.

+1

괜찮아 보이는데 synthezise 호출을 게시하지 않으 셨다고 생각합니다. – CarlJ

+0

헤더에 속성을 선언했지만 '@ synthesize' 또는'@ dynamic'을 사용하지 않았습니다. – Jasarien

답변

0

예, 누출 가능성이 있습니다. viewDidLoad은 잠재적으로 여러 번 호출 될 수 있으며,이 경우 메모리 누수가 발생합니다. viewDidLoad에 보관하는 모든 내용은 늦어도 viewDidUnload (그리고 dealloc)으로 발표 (및 nil으로 설정)해야합니다.

viewDidLoad에 합성 된 setter를 사용했다면 (거의 항상 그렇듯이) viewDidLoad이 실행될 때마다 새 스레드를 할당 할 때마다 이전 스레드 객체가 해제되기 때문에 문제가 완화됩니다.

+0

감사합니다. 귀하의 답변은 매우 유용합니다! – jxdwinter