2

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!

6
  • How are you allocating/initializing cycloneDatabase? Commented Aug 1, 2011 at 21:04
  • 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.) Commented Aug 1, 2011 at 21:21
  • <__NSArrayM 0x5a4e7f0>( <StormData: 0x5a581a0> ) Commented Aug 1, 2011 at 21:26
  • that looks legit. it seems I do have mem management problems, as perception says Commented Aug 1, 2011 at 21:27
  • 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.) Commented Aug 1, 2011 at 21:32

1 Answer 1

4

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: :)

Sign up to request clarification or add additional context in comments.

2 Comments

Agree, and would add further that since NSArray's can't hold nils, the debugger is probably lying somehow. In the absence of anything else, I'd guess the array is actually fine at this point, and if @Dmitri can't access the elements later, then something else is going on elsewhere.
@quixoto thanks for the gdb tip. The debugger not showing me the values i wanted to see was at least part of the problem. as for the rest of it, i gotta figure it out eventually... I guess this'll teach me a lesson in unit testing and keeping code organized. (i.e. when in comp. sci. territory, so as the comp-sci majors/professionals)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.