I find some same topic in stackoverflow, but i can't solve my problems.
This is my code
In my .h
@property (nonatomic, retain) NSMutableArray *favoriteShops;
My .m
NSString *idStr = @"";
NSString *shopTypeId = @"";
for (SHDFavoriteShopView *favoriteShopView in favoriteShops) {
idStr = [favoriteShopView valueForKey:kId];
shopTypeId = [favoriteShopView valueForKey:kShopTypeId];
if (tappedView.tag == [idStr intValue]) { // Crash here
shop.shopType = [shopTypeId intValue];
break;
}
}
I have problem sometime, not usually.
Could you please help me.
Thanks you
It's an indication that the string you are accessing (
idString
in this case) has already been freed. There are a number of reasons why this can happen. If the string was originally allocated via an auto-released method (such as[NSString stringWithFormat:@"..."]
), and the string got auto-released. Or if you allocated the string, but later released it by explicitly calling[idStr release]
. You need to make sure that you are not re-using a string after it's already been released. That can be tricky!