views:

352

answers:

2

here is the code: http://pastie.org/562956

this code crashes on the call to itemsArray.count on "didSelectRowAtIndexPath". I don't get why... itemsArray is accessed for other methods like "numberOfRowsInSection". why would it all of a sudden get dereferenced ( I assume that is what is happening).

here is the output (dunno what's up with "unable to read unknown load command 0x22" either)

[Session started at 2009-07-28 22:11:50 -0600.] Warning - No location found for "NSUserDefaults-Optimize.m:81" GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 56173. unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 unable to read unknown load command 0x22 2009-07-28 22:11:55.545 Send2iPhone[56173:20b] Load items 2009-07-28 22:11:55.629 Send2iPhone[56173:20b] cellforrow 0 2009-07-28 22:11:55.634 Send2iPhone[56173:20b] value=(null) 2009-07-28 22:11:55.644 Send2iPhone[56173:20b] cellforrow 1 2009-07-28 22:11:55.645 Send2iPhone[56173:20b] value=(null) 2009-07-28 22:11:55.654 Send2iPhone[56173:20b] cellforrow 2 2009-07-28 22:11:55.658 Send2iPhone[56173:20b] value=(null) 2009-07-28 22:11:55.659 Send2iPhone[56173:20b] cellforrow 3 2009-07-28 22:11:55.663 Send2iPhone[56173:20b] value=(null) 2009-07-28 22:11:57.724 Send2iPhone[56173:20b] row = 0 Program received signal: “EXC_BAD_ACCESS”. kill quit

The Debugger has exited with status 0.(gdb)

+2  A: 

You are not claiming ownership of itemsArray, so it's being freed by the autorelease pool at some point. You could solve it by setting the variable using an accessor that properly retains and releases. Also, if you haven't, you should read the Cocoa memory management guidelines.

Chuck
+2  A: 

Chuck has it right, you aren't retaining the array.

One fix is to make itemsArray a property of the controller so in the header

@interface RootViewController : UITableViewController {
    NSArray *itemsArray;
    NSString *test;

}

//add the property directive for itemsArray and tell it to use retain
@property (nonatomic, retain) NSArray *itemsArray;

and in the .m

@implementation RootViewController
// add the synthesize for itemsArray property
@synthesize itemsArray;


// when you set the value of itemsArray use self.itemsArray this will properly retain the array
self.itemsArray = [NSArray arrayWithContentsOfURL:plistURL];


// release the itemsArray in dealloc
- (void)dealloc {
  [itemsArray release];
  [super dealloc];
}
paulthenerd