I am getting memory leak theFileName = [[responseString lastPathComponent]stringByDeletingPathExtension];
theFileName is a global variable. I have synthesized it and
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
// Custom initialization
theFileName = [[NSString alloc] init];
}
return self;
}
- (void)requestFinished:(ASIHTTPRequest *)request{
//internally calls this function
// Use when fetching text data
NSString *responseString = [request responseString];
//NSLog(@"the responsestring for download is:%@",responseString);
theFileName = [[responseString lastPathComponent]stringByDeletingPathExtension];
//NSLog(@"the theFileName for download is:%@",theFileName);
//adds extension .jpg to file name
NSString *jpg=@".jpg";
NSString *addjpg=[theFileName stringByAppendingString:jpg];
//NSLog(@"append %@",addjpg);
}
Released it in dealloc.
-(void)dealloc
{
[thefileName release];
}
}
Here are a few things that might help.
You’re not calling
super‘sdeallocmethod withinself‘sdealloc. For example,- (void) dealloc{
[self.theFileName release];
[super dealloc];
}
You’re not using the getters and setters that come with synthesizing a property, and we don’t know what property you’ve used with theFileName. If you’ve got a retaining property, i.e. a statement like
@property (copy) NSString * theFileNamethen you should use the setter so that you don’t trip up on retain counts. For example,{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
// Custom initialization
NSString * aFileName = [[NSString alloc] init];
[self setTheFileName:aFileName];
[aFileName release];
}
return self;
}
is better.