In my viewController.m I have this code:
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];
In viewController.h I have this code:
@interface ViewController : UIViewController
{
myMovie * movie;
UILabel * nameLbl;
}
@property (nonatomic, retain) myMovie * movie;
@property (nonatomic, retain) UILabel * nameLbl;
And 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
Of course this is only the necessary code. I can’t figure out why it is leaking. I don’t know if this is the cause but my application crashes.
The line that’s leaking is the one above:
self.movie = [[myMovie alloc]init];Change it to
self.movie = [[[myMovie alloc]init] autorelease];or add[self.movie release];as the line immediately afterwards.