.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
.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];
}
Is there a leak of memory about tableViewThread and headViewThread ?
And if there is a leak, what should I do with this problem?
Thank you in advance!
Yes, there is a potential leak.
viewDidLoadcan potentially be called multiple times, in which case you would see memory leaks. Everything you retain inviewDidLoadshould be released (and set tonil) at the latest inviewDidUnload(and also indealloc).Had you used the synthesized setters in
viewDidLoad(as you should almost always do), the problem would be mitigated because every timeviewDidLoadwas executed, the old thread objects would get released when you assigned the new ones.