Iphone App Crashes - But sometime works(50%-50%)

Discussion in 'iOS Programming' started by amit-battan, Mar 4, 2010.

  1. amit-battan macrumors newbie

    Joined:
    Sep 10, 2009
    #1
    Hi All

    I am using following code for showing a next view(tableview) in Iphone app.

    It sometime works and some time app crashes without any exception log

    NSLog(@"Ok"); is log everytime 50% attempts application crashes

    Code:
    -(IBAction)statusInitiationButAction:(id)sender{
        @try {
            NSArray *tempArrIniId = [eventInitiationArray valueForKey:@"act_id"];
            int s;
            if([tempArrIniId containsObject:selectedInitiateId]){
                s=[tempArrIniId indexOfObject:selectedInitiateId];
            }
            [tempArrIniId release];
            NSString *selStatusId = [NSString stringWithString:[[eventInitiationArray objectAtIndex:s] objectForKey:@"status_id"]];
    
            for (int i=0; i<[statusInitiationArray count]; i++) {
                id statusDict = [statusInitiationArray objectAtIndex:i];
                if ([selStatusId intValue] == [[statusDict objectForKey:@"id"] intValue]) {
                    [statusDict setValue:@"1" forKey:@"selected"];
                    [statusInitiationArray replaceObjectAtIndex:i withObject:statusDict];
                }else {
                    [statusDict setValue:@"0" forKey:@"selected"];
                    [statusInitiationArray replaceObjectAtIndex:i withObject:statusDict];
                }
            }
            NSLog(@"statusInitiationTable...%@",statusInitiationArray);
            [statusInitiationTable.tableView reloadData];
            [[self navigationController] pushViewController:statusInitiationTable animated:YES];
            NSLog(@"ok");
        }@catch (NSException * e) {
            NSLog(@"statusInitiationButAction....%@",e);
        }
    }
    
    Can anybody guide me about the problem.

    Thanks
    Amit Battan
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You are releasing an object when you should not. You did not create tempArrIniId via alloc/init or copy so you should not release it. Go at read the Memory Management document (especially the page I linked to).
     
  3. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #3
    This section sets the value of s if the id exist in the array and only in the array. You then use the int s in the next statement out side of the check. What happens if s is not set. If the value is not in the array s is just a nil value, therefore you will not be able to get the value for
    Code:
    [eventInitiationArray objectAtIndex:s]
     

Share This Page