开发者

EXC_BAD_ACCESS error in during fetching data from custome objects

开发者 https://www.devze.com 2023-03-25 09:15 出处:网络
I had stored custom objects data in Array. I am fetching data from Array of custom objects in a function. when I am calling function for first time it is working good but When I am calling it again an

I had stored custom objects data in Array. I am fetching data from Array of custom objects in a function. when I am calling function for first time it is working good but When I am calling it again and again I am getting EXC_BAD_ACCESS.

Here is function details.

-(void) facebookDisplayFunction:(int)atIndex {


FacebookWallData *wall = (FacebookWallData *)[facebook_wallDataArray objectAtIndex:atIndex];


NSString *friendID= wall.actor_id;
NSString *linkFetch= wall.permalink;
NSString* postID=wall.postId;

NSNumber *countNumber;

NSString *friendName=@"";
NSString* profileThumImage=@"";

for(int i=0; i< [facebook_LikesArray count];i++) {

    FacebookLikes* countValues=[[FacebookLikes alloc]init开发者_如何学Python];
    countValues=[facebook_LikesArray objectAtIndex:i];

 //   NSLog(@" postId_wall %@  LikePostId = %@",postID,countValues.PostID);
    if([postID isEqualToString:countValues.PostID]) {
        countNumber=countValues.Count;

        if(countNumber>0) 
            friendID=countValues.Friends;

        [countValues release];
        break;
    }

    [countValues release];
}


for(int i=0;i< [facebook_FreindsArray count];i++) {

    FacebookFreinds* friendsRecord=[[FacebookFreinds alloc]init];
    friendsRecord=[facebook_FreindsArray objectAtIndex:i];

    if([friendID isEqualToString:friendsRecord.UID]) {
        friendName=friendsRecord.name;
        profileThumImage=friendsRecord.pic_smal;
        [friendsRecord release];
        break;
    }
    [friendsRecord release];
 }

// Adding values in table //





[imageData addObject:@"facebook.png"]; 
[tableList addObject:wall.messages];
[profileUserName addObject:friendName];
[linksOfFacebookData addObject:linkFetch];
[RetweetAndLikeData addObject:@"5"];
[favedProfileThumb addObject:profileThumImage];
[twitterPostID addObject:@""];
[eachPostUID addObject:friendID];

  [wall release];

}

And here I am calling function. [self facebookDisplayFunction:0]; [self facebookDisplayFunction:0]; // EXC_BAD_ACCESS error here.


Why are you allocating an object like this FacebookLikes* countValues=[[FacebookLikes alloc]init] and then assigning to this same variable the instance inside the array with this code countValues=[facebook_LikesArray objectAtIndex:i] and later on you release it with this [countValues release]? You don't know what you are doing.

Try changing this:

FacebookLikes* countValues=[[FacebookLikes alloc]init];
countValues=[facebook_LikesArray objectAtIndex:i];

to this

FacebookLikes* countValues = [facebook_LikesArray objectAtIndex:i];

and remove all occurrences of [countValues release]. Do the same for the friendsRecord in the second for-loop. Also, what is the [wall release]? Remove it!

You should not allocate any of these objects because you are actually obtaining them from that array, and not creating a new instance. That just creates a leak in your code. You should not release any of these objects because they are retained by the array, and it is responsible for releasing them whenever they are removed from the array or after the array is destroyed/deallocated. Please, rtfm


If you get the error on the line:

 [self facebookDisplayFunction:0];

it seems to me that most likely the object pointed by self has been deallocated. So, the problem would not be in facebookDisplayFunction...

Could you review how you create the object pointed by self, or post the code if you need more help?

0

精彩评论

暂无评论...
验证码 换一张
取 消