在我viewController.m
我有这段代码:
self.movie = [[myMovie alloc]init];
self.movie.name = @"Iron man 2"; \\this line leaks
...
nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(30, 20, 200, 20)]; \\this line leaks
nameLbl.backgroundColor = [UIColor clearColor];
在viewController.h
我有这段代码:
@interface ViewController : UIViewController
{
myMovie * movie;
UILabel * nameLbl;
}
@property (nonatomic, retain) myMovie * movie;
@property (nonatomic, retain) UILabel * nameLbl;
myMovie.h:
{
NSString* name;
}
@property (nonatomic, retain) NSString* name;
myMovie.m:
#import "myMovie.h"
@implementation myMovie
@synthesize name, gross, desc;
-(void) dealloc
{
self.name = nil;
self.gross = nil;
self.desc = nil;
[super dealloc];
}
@end
当然这只是必要的代码。我无法弄清楚它为什么会泄漏。我不知道这是不是原因,但是我的应用程序崩溃了。
答案 0 :(得分:4)
泄漏的行是上面的行:self.movie = [[myMovie alloc]init];
将其更改为self.movie = [[[myMovie alloc]init] autorelease];
或在之后立即添加[self.movie release];
。