0

。H:

#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

米:

@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 的内存泄漏?如果有泄漏,我应该如何处理这个问题?先感谢您!

4

1 回答 1

0

是的,有潜在的泄漏。viewDidLoad可能会被多次调用,在这种情况下您会看到内存泄漏。您保留的所有内容viewDidLoad都应nil最迟在viewDidUnload(以及)中发布(并设置为dealloc)。

如果您在其中使用了合成的 setter viewDidLoad(几乎总是应该这样做),那么问题就会得到缓解,因为每次viewDidLoad执行时,旧的线程对象都会在您分配新的线程对象时被释放。

于 2012-06-01T15:19:06.267 回答