in Education by
I have a class that logs on to a server and retrieves some data. The data is put in a NSMutableArray, converted to a NSArray and returned. The code is called like this: 1. NSLog(@"Filling tempoArray"); 2. NSArray *tempoArray = [myLogin getRoster:[self employmentnumber] online:YES]; 3. NSLog(@"Setting calendarItems with tempoArray"); In the 'myLogin' object, the array is created like this: 4. NSMutableArray *calendarItems = [[NSMutableArray alloc]init]; 5. Filling the array... 6. NSArray *tempoArray2 = [[NSArray alloc]initWithArray:calendarItems]; //Converting from mutabe to a normal array 7. NSLog(@"tempoArray2 filled with calendarItems. tempoArray2.count:%d", tempoArray2.count); 8. return tempoArray2; The NSLog in lines 1 and 7 are written to the console but line 3 is never seen, so it crashes in line 2. I wonder if I the tempoArray2 is released to soon? And if so, how can I avoid that with ARC? The error only appears when I download the app from AppStore, I have never seen any problem with this in any debug scenario. How can that be? This is why I use the console log to pinpoint the error. The symbolication in XCode isn't working very good. EDIT Here is 'line 5' It is parsing a web page. NSString *heleTeksten = [[NSString alloc] initWithData:self.rosterurlmutabledata encoding:NSISOLatin1StringEncoding]; //NSLog(@"heleteksten%@", heleTeksten); NSArray *lines = [heleTeksten componentsSeparatedByString:@"\n"]; NSString *searchFor = @""].location != NSNotFound) { line = [self removeBfromLine:line]; } if ([line rangeOfString:@";"].location != NSNotFound) { line = [line stringByReplacingOccurrencesOfString:@";" withString:@""]; } secondRange = [line rangeOfString:@"style='color: '>"]; if (secondRange.location != NSNotFound) { firstPlace = secondRange.location + 16; } NSString *partOfLine; partOfLine = [line substringFromIndex:firstPlace]; secondRange = [partOfLine rangeOfString:@"<"]; if (secondRange.location != NSNotFound) { //NSLog(@"partOfLine = [partOfLine substringToIndex:secondRange.location] Line:%@", line); partOfLine = [partOfLine substringToIndex:secondRange.location]; } else { //TODO: Endre errorLog her til myErrorReport: // [self errorLog:[@"'<' not found in partofline. Line: " stringByAppendingString:line]]; } partOfLine = [partOfLine stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; if ([partOfLine length]>0 || [line rangeOfString:@"param11"].location != NSNotFound) { if ([line rangeOfString:@"'param1'"].location != NSNotFound ) // Date-line { param1date = nil; param1date = [NSString stringWithString:partOfLine]; } else if ([line rangeOfString:@"param7"].location != NSNotFound) // STD-line { param7std = [NSString stringWithString:partOfLine]; } else if ([line rangeOfString:@"param8"].location != NSNotFound) // STA-line { param8sta = [NSString stringWithString:partOfLine]; } else if ([line rangeOfString:@"param5"].location != NSNotFound) // CheckIn-line { param5checkIn = [NSString stringWithString:partOfLine]; } else if ([line rangeOfString:@"param6"].location != NSNotFound) // Orig-line { param6from = [NSString stringWithString:partOfLine]; } else if ([line rangeOfString:@"param9"].location != NSNotFound) // Dest-line { param9to = [NSString stringWithString:partOfLine]; } else if ([line rangeOfString:@"param2"].location != NSNotFound) // Duty-line { if ([userdefaults boolForKey:@"inklDutyCodes"]) { param2duty = [NSString stringWithString:partOfLine]; } } else if ([line rangeOfString:@"param3"].location != NSNotFound) // FlightNo-line { param3activity = [NSString stringWithString:partOfLine]; } else if ([line rangeOfString:@"param11"].location != NSNotFound) // Last line. Save calendarItem { calendarItem *newCalendarItem = [[calendarItem alloc]init]; // currentDate = [self makeNormalDate:partOfLine forAirport:param6from]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; if (param7std == nil) // = whole day event { [newCalendarItem setWholeDay:YES]; [newCalendarItem setSubject:param3activity]; if (param6from == nil) { [newCalendarItem setStartTime:[self makeNormalDate:param1date forAirport:@"OSL"]]; } else { [newCalendarItem setStartTime:[self makeNormalDate:param1date forAirport:param6from]]; } [newCalendarItem setEndTime:newCalendarItem.startTime]; } else { if (param2duty != nil) { [newCalendarItem setDuty:[NSString stringWithString:param2duty]]; } else { [newCalendarItem setDuty:[NSString stringWithString:[NSString string]]]; } [newCalendarItem setWholeDay:NO]; if (param6from != nil) [newCalendarItem setOrig:param6from]; else [newCalendarItem setOrig:[NSString string]]; if (param9to != nil) [newCalendarItem setDest:param9to]; else [newCalendarItem setOrig:[NSString string]]; if (param3activity != nil) { if ([param3activity integerValue]) //Sjekker at det her kun er tall { [newCalendarItem setSubject:[@"SK" stringByAppendingString:param3activity]]; } else { [newCalendarItem setSubject:param3activity]; } } else { [newCalendarItem setSubject:[NSString string]]; } if (param7std != nil) { if ([param7std length] == 4) { NSString *dateAndTimeString = [param1date stringByAppendingString:param7std]; NSLocale * enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [dateFormatter setLocale:enUSPOSIXLocale]; NSTimeZone *thisTimeZone; if (param6from != nil) { thisTimeZone = [self timeZoneForAirport:param6from]; } if (thisTimeZone == nil) { thisTimeZone = [NSTimeZone timeZoneWithName:@"Europe/Oslo"]; } [dateFormatter setTimeZone:thisTimeZone]; [dateFormatter setDateFormat:@"ddMMMyyHHmm"]; [newCalendarItem setStartTime:[dateFormatter dateFromString:dateAndTimeString]]; if (param5checkIn != nil) { calendarItem *checkInCalendarItem = [[calendarItem alloc]init]; NSString *checkinTimeString = [param1date stringByAppendingString:param5checkIn]; [checkInCalendarItem setWholeDay:NO]; [checkInCalendarItem setStartTime:[dateFormatter dateFromString:checkinTimeString]]; [checkInCalendarItem setEndTime:[checkInCalendarItem startTime]]; [checkInCalendarItem setSubject:@"Check In"]; [[self calendarItems] addObject:checkInCalendarItem]; checkInCalendarItem = nil; } } else { [mydelegate myErrorLogFromClass:self andMethod:@"getRoster:Online:" withFreeText:[NSString stringWithFormat:@"STD ikke 4 lang. Line: %@", line] andListofIvars:nil]; } } else { [mydelegate myErrorLogFromClass:self andMethod:@"getRoster:Online:" withFreeText:[NSString stringWithFormat:@"STD er nil. Line: %@", line] andListofIvars:nil]; } if (param8sta != nil) { if ([param8sta length] == 4) { NSString *dateAndTimeString = [param1date stringByAppendingString:param8sta]; NSLocale * enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [dateFormatter setLocale:enUSPOSIXLocale]; NSTimeZone *thisTimeZone2; if (param9to != nil) { thisTimeZone2 = [self timeZoneForAirport:param9to]; } else if (param6from != nil) //Kan skje ved stby { thisTimeZone2 = [self timeZoneForAirport:param6from]; NSLog(@"thisTimeZone2 satt til param6From for param9To er nil. Dato:%@", dateAndTimeString); } if (thisTimeZone2 == nil) { thisTimeZone2 = [NSTimeZone timeZoneWithName:@"Europe/Oslo"]; NSLog(@"thisTimeZone2 satt til OSL. param9to er nil."); } [dateFormatter setTimeZone:thisTimeZone2]; [dateFormatter setDateFormat:@"ddMMMyyHHmm"]; NSDate *tempoDate = [dateFormatter dateFromString:dateAndTimeString]; if([tempoDate compare:newCalendarItem.startTime] == NSOrderedAscending) { tempoDate = [NSDate dateWithTimeInterval:86400 sinceDate:tempoDate]; } [newCalendarItem setEndTime:tempoDate]; } else { [mydelegate myErrorLogFromClass:self andMethod:@"getroster:online:" withFreeText:[NSString stringWithFormat:@"STA-felt ikke 4 lang. Line: %@",line] andListofIvars:nil]; } } else { [mydelegate myErrorLogFromClass:self andMethod:@"getroster:online:" withFreeText:[NSString stringWithFormat:@"STA-felt er nil. Line: %@",line] andListofIvars:nil]; } } if (param3activity != nil) { if ([param3activity rangeOfString:@"GO"].location == NSNotFound && [param3activity rangeOfString:@"VO"].location == NSNotFound) { if ([self itemOkAccordingToPreferences:newCalendarItem]) { [[self calendarItems] addObject:newCalendarItem]; } } } param2duty = nil; param3activity = nil; param6from = nil; param7std = nil; param8sta =nil; param9to = nil; param5checkIn = nil; } } //End of if ([partOfLine length]>0) } } } // End of for (NSString* line in lines) NSLog(@"Ferdig med å tygge dataene. Funnet %d calendarItems", [[self calendarItems] count]); NSArray *tempoArray2 = [[NSArray alloc]initWithArray:[self calendarItems]]; NSLog(@"tempoArray2 fyllt med calendarItems. tempoArray2.count:%d", tempoArray2.count); return tempoArray2; JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If this really is all the code, then I can think of some scenarios where this would crash. First, if you have multiple threads, it's very likely you're crashing on another thread. If this is the only thread, then I would suspect somewhere in "line 5" you create data that is incorrectly memory managed. In ARC, this requires either that you're calling out to non-ARC code, or you're doing __bridge casts at some point, or you incorrectly manage malloc memory (perhaps in the dealloc of something created in "line 5"). At line 2, tempoArray may be immediately deallocated if it is not used after line 2. If it is used after line 2, then it is almost inconceivable that it would be released too early unless you've done something really strange (like having the return type of getRoster... be __unsafe_unretained NSArray*). Another possibility is if you're smashing your own stack. This can happen if you allocate C arrays or strings on your stack and then write off the end of them. This would be most likely in "line 5." The fact that you see this in the field suggests that it may be optimization related. Make sure to test with Release mode. Your naming conventions are incorrect, which can create problems in ARC code, though I doubt this is the actual problem. The leading get in getRoster:online: should be removed. A leading get indicates that the method returns its result by reference. That said, I don't believe ARC applies any special memory management in this case, so I don't think it's causing your crash. See the KVC guide for full details on correct naming so that ARC knows what you're doing. The fact that symbolication isn't working well suggests that you might be looking at a different dSYM file than the code you shipped. Make sure you always save the dSYM and binary of the package you send to app store. Xcode uses spotlight to find a matching dSYM.

Related questions

0 votes
    So I've got some C code: #include #include /* putting one of the "char*"s here causes a segfault ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    static storage is decided at compilation time. However, consider the scenario where we have lot of lazy ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    static storage is decided at compilation time. However, consider the scenario where we have lot of lazy ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    static storage is decided at compilation time. However, consider the scenario where we have lot of lazy ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    In my signal.h file I have added a signal handler like this: #define SIG_WPG ((__sighandler_t)3) and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    What are the common causes of the segmentation fault in C?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    What is the difference between Segmentation fault and Bus error?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    What is segmentation fault in C?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    When might you use a CFArray/Dictionary instead of a NSArray/Dictionary?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    Explain when to use NSArray and NSMutableArray. Which one is faster and threadsafe in Objective-C?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    numbers. 4. (a) When running a particular program with N memory accesses, a computer with a cache and paged ... the system ? cribe Select the correct answer from above options...
asked Dec 5, 2021 in Education by JackTerrance
0 votes
    Which of the following option helps Azure maintain a high availability and fault tolerance when deploying and upgrading applications ... IP address 4. Scale set 5. Replica set...
asked Sep 22, 2021 in Technology by JackTerrance
+1 vote
    Which of the following helps Azure maintain high availability and fault tolerance when deploying and upgrading applications?...
asked Oct 20, 2020 in Technology by JackTerrance
...