2
votes

I am trying to add objects to an NSMutableArray (it has been properly alloced and inited). After running addObject, the debugger says the array has the correct number of elements in it, but all of the elements are pointing to 0x0 . I cannot access the elements later in the program. the screenshot is here

http://imageshack.us/photo/my-images/818/screenshot20110801at344.png/

what am I missing?

note that the "storm" object that gets added to the array looks good in the debugger...

thanks!

1
How are you allocating/initializing cycloneDatabase? - highlycaffeinated
What do you get if you execute po cycloneDatabase in the console/output window while at this breakpoint? (I find the GUI variable interpretation notoriously unreliable.) - Ben Zotto
<__NSArrayM 0x5a4e7f0>( <StormData: 0x5a581a0> ) - Dmitri
that looks legit. it seems I do have mem management problems, as perception says - Dmitri
Yes, though that looks like an array with only one object (the StormData) in it. I'd expect to also see the string. (You can continue to test the objects with the debugger's po command, even on the address, e.g. po 0x5a581a0 and see what you get.) - Ben Zotto

1 Answers

4
votes

From the code you've posted, everything looks fine. If you were overreleasing you wouldn't have nilled out pointers in the array, and you have two elements which makes sense seeing as you call addObject: twice. The one thing that might be wrong is your initialisation of the cycloneDatabase array. Check you're initialising it correctly cycloneDatabase = [[NSMutableArray alloc] init]. I can't say I've ever seen this one before though.

P.S. Slight nitpick, you shouldn't use get* in methods, like your getCycloneWithName:. get* implies you are returning by reference, which in this case you aren't, so it should really be just cyloneWithName: :)