views:

34

answers:

1

Hi all! I made my own class derived by NSObject, and here is my code:

-(void) parseRow:(NSDictionary*) dictionary {
    NSArray* arName = [[dictionary valueForKey:displayname] componentsSeparatedByString:@"+"];
    [self setDriverName:[arName objectAtIndex:0]];
    [self setDriverSurname:[arName objectAtIndex:1]];
    [arName release]; // this give problem!
}

and in my view:

driverStats = [[DriverStats alloc] init];

// driverStats is declared in the header:
DriverStats* driverStats;
@property (nonatomic,retain) DriverStats* driverStats;

[driverStats parseRow:dictionary];

If I add [arName release] in my class, when I exit from parseRow method, I have the EXC_BAD_ACCESS error.... but it's wrong?? I used array and after I released... I think that the error will be if I didn't release the pointer.. or not??? thanks in advance

+5  A: 

The problem is easy to solve. Your NSArray *array only have 0 retainCount. Because you use a factory method componentsSeparatedByString:, it returns you an autoreleased array already. So, you don't need to release your array anymore.

Another thing you need to care about is the setDriverName: and setDriverSurname:, make sure you retain/copy the object there otherwise, when the array is released, those objects are also released and EXEC_BAD_ACCESS again

vodkhang
thanks! my drivername and driversurname properties are declared:`@property (nonatomic, retain) NSString* driverName;``@property (nonatomic, retain) NSString* driverSurname;`but a similar property integer is declared:`@property (nonatomic) int points;`
ghiboz
that should be correct. So, you don't need to worry about the setter any more:)
vodkhang