I’m getting a leak from using substringWithRange as shown in the line of code below. I though all these functions were Autorelease and you didnt need to alloc/release them manually.
NSCFString is the object being leaked.
What is it I am doing wrong?
aLTR.drew = [substring substringWithRange:NSMakeRange(match.location+1, (match2.location-(match.location+1)))];
What I am trying to do is extract a substring and store it into my storage class. Code for that below.
#import <Foundation/Foundation.h>
@interface LeagueTableRow : NSObject
{
NSString *_teamName;
NSString *_played;
NSString *_won;
NSString *_drew;
NSString *_lost;
NSString *_goalsFor;
NSString *_goalsAgainst;
NSString *_points;
}
@property(nonatomic, copy) NSString *teamName;
@property(nonatomic, copy) NSString *played;
@property(nonatomic, copy) NSString *won;
@property(nonatomic, copy) NSString *drew;
@property(nonatomic, copy) NSString *lost;
@property(nonatomic, copy) NSString *goalsFor;
@property(nonatomic, copy) NSString *goalsAgainst;
@property(nonatomic, copy) NSString *points;
-(id)init;
@end
#import "LeagueTableRow.h"
@implementation LeagueTableRow
@synthesize teamName = _teamName;
@synthesize played = _played;
@synthesize won = _won;
@synthesize drew = _drew;
@synthesize lost = _lost;
@synthesize goalsFor = _goalsFor;
@synthesize goalsAgainst = _goalsAgainst;
@synthesize points = _points;
-(id)init
{
self = [super init];
return self;
}
-(void) dealloc
{
self.teamName = nil;
self.played = nil;
self.won = nil;
self.drew = nil;
self.lost = nil;
self.goalsFor = nil;
self.goalsAgainst = nil;
self.points = nil;
[super dealloc];
}
@end
I’m quiet surprised I got some leaks I though I was managing the memory quiet tidily.
Thanks for the advice and tips.
-Code
In your dealloc, simply release all the string ivars:
Alternatively, you could do:
I prefer to use the ivars directly, in such situations.