3

I'm simply trying to save this array to the user defaults and it will crash at random. Sometimes it works, sometimes it gives me the EXC_BAD_ACCESS. Am I not releasing something properly?

- (void)setTextValue:(NSString *)valueText indexToSet:(NSUInteger)index
{
    [self.pageData replaceObjectAtIndex:index withObject:valueText];
    [[NSUserDefaults standardUserDefaults] setObject:self.pageData forKey:@"mynotes"];
}

Here is the method that i've determined is causing the errors. It was a method already created by Xcode that I added my own custom code to.

- (nbookDataViewController *)viewControllerAtIndex:(NSUInteger)index storyboard:(UIStoryboard *)storyboard
{   
    nbookDataViewController *dataViewController = [storyboard instantiateViewControllerWithIdentifier:@"nbookDataViewController"];
    if (self.pageData.count > 0 && index < self.pageData.count)
    {
        NSString *val = (NSString *)[self.pageData objectAtIndex:index];
        dataViewController.dataObject = val;
    }
    else
    {
        NSDate *date = [NSDate date];
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"MMMM d, YYYY"];
        NSString *dateString = [dateFormat stringFromDate:date];
        //[dateFormat release];
        [self.pageData addObject:dateString];
        dataViewController.dataObject = (NSString *)[self.pageData objectAtIndex:index];
    }
    dataViewController.myModel = (nbookModelController *)self;
    dataViewController.dIndex = index;
    //[self.mySaveData setObject:self.pageData forKey:@"mynotes"];
    return dataViewController;
}
Rob Lester
  • 83
  • 6
  • 2
    Can you post the entire console error? Thanks – MaTTP Sep 07 '12 at 12:20
  • You are either somewhere overreleasing `valueText` or releasing `self.pageData` not reinitializing. – A-Live Sep 07 '12 at 12:23
  • your index could be out of bounds for the pageData (assuming some kind of mutable array). – YvesLeBorg Sep 07 '12 at 12:28
  • or could be an `NSRangeException` error. make sure you have the data in self.pageData objectAtIndex:index – janusfidel Sep 07 '12 at 12:28
  • I need help with understanding this release business. I'm a .net developer usually... I make variable, I use it, it never causes memory errors. However, I can't easily use variables here. It's rather irritating. – Rob Lester Sep 07 '12 at 17:46
  • May be it reached indexOutException. – Vineesh TP Sep 10 '12 at 05:14
  • I'm also getting a sigabrt error. I'm starting to wonder if this has anything to do with my code at all. It's all random. It will work flawlessly for a few minutes and then crash. – Rob Lester Sep 11 '12 at 02:24

1 Answers1

1

This tip will allow you code to break on the exception and let you check directly why this is happening: https://stackoverflow.com/a/616526/46970

Community
  • 1
  • 1
Kobski
  • 1,636
  • 15
  • 27