-[CFString intValue]: message sent to deallocated instance 0xa3a2610

StackOverflow https://stackoverflow.com/questions/18627213

  •  27-06-2022
  •  | 
  •  

Вопрос

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!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top