10

I've got an app that gets information from a SOAP web service and I want to display the results in a UITableView.

I had a previous version of this app and I'm creating a new version to basically clean things up and get rid of a bunch of legacy code that's deprecated and no longer used.

In the previous version, this worked well. In the new version, not so much.

Basically, the current scenario is returning 3 strings that I'm trying to use as the basis for the data in my UITableView.

I'm struggling with this issue because it's so stinkin' hard to track down EXC_BAD_ACCESS errors!

(Parenthetically, if someone has a way to make the debug experience more like Visual Studio, I'd love to hear it! It's so frustrating to not have any idea which line caused the error, and also to not be able to look through my local variables at the time of the crash to see what's what. I've already added in the exception breakpoint, but that doesn't seem to do much.)

Anyway, the line that's causing the error APPEARS to be:

return [[self Libraries] count];

It occurs in tableView:numberOfRowsInSection:.

The error message I get APPEARS to reference a string that should be stored in the NSMutableArray [self Libraries].

What's going on here?
I'm using ARC, so shouldn't all of my memory management be correctly handled?
I don't have any manual release statements in my code ANYWHERE!

Please help me fix this!

Philipp Schlösser
  • 5,179
  • 2
  • 38
  • 52
mbm29414
  • 11,558
  • 6
  • 56
  • 87
  • 1
    ARC only *simplifies* memory management. It does not take over completely for you. – Jonathan Grynspan Oct 29 '11 at 16:40
  • 4
    Boy, that's an unhelpful comment. How does that even point me toward solving my problem? Basically, my questions is this: How can I be over-releasing something WHEN I HAVE ABSOLUTELY ZERO `release` STATEMENTS IN MY CODE? Thanks! – mbm29414 Oct 29 '11 at 16:47
  • I've been using Instruments to take a look at this silliness. Basically, it appears that a particular method will sometimes do a retain/release, but sometimes it does a retain/release/release. I'm assuming this is where the problem lies, but I can't figure out how to determine WHERE that problem is occurring. Also, `[object retainCount]` is forbidden using ARC. How, then, do I track this error better? – mbm29414 Oct 29 '11 at 18:40
  • You have no `release` statements in your code because GCC put them there for you. *You still have to know where they would otherwise go*. – Jonathan Grynspan Oct 29 '11 at 18:58
  • @Jonathan Grynspan While your intent is good: "learn more" that partially applies here because ARC does do things that we programmers can't, particularly when returning autoreleased objects. What would probably help a lot is for the OP to study the ARC documentation, not dissimilar to your advice. In particular following naming conventions are mandatory for ARC to be successful and the OP is at least in some instances ignoring them. – zaph Oct 29 '11 at 19:29
  • ARC does nothing we can't already do. It just streamlines it. You still need to understand what it's doing under the covers in order to avoid these sorts of problems. – Jonathan Grynspan Oct 29 '11 at 21:14
  • 2
    @Jonathan Grynspan: Really? THAT'S NOT TRUE!!! For instance, using ARC, retain, release, autorelease and even retainCount are FORBIDDEN by the compiler! I understand memory management. I know where those statements should go. As you see in my post below, it turns out that my code was fine and it was an Xcode 4.2 beta bug. I don't think YOU understand ARC very well. – mbm29414 Oct 30 '11 at 19:53
  • @mbm30075 Pretty sure I do, but this isn't the place for that sort of discussion. – Jonathan Grynspan Oct 31 '11 at 00:46
  • 1
    @JonathanGrynspan Then why would you say "It does not take over completely for you"? Actually, that's exactly what it does. It specifically does just that, INTENDING to make memory management automatic. To that end, it specifically FORBIDS manual memory management. What exactly does that leave with respect to traditional memory management? – mbm29414 Oct 31 '11 at 01:55
  • Perhaps you should read up on it some more. :) This is not the appropriate place on SO for this discussion, however. – Jonathan Grynspan Oct 31 '11 at 13:42
  • 1
    @JonathanGrynspan Answering with "I'm not going to talk about that" makes it appear that you don't have a real answer. My question still remains: What traditional, manual memory management is left when using ARC? Answer: None! It specifically takes that away from you. – mbm29414 Nov 01 '11 at 12:27
  • New questions should be asked in *new questions*, not comment threads. I'd be happy to answer you in a new post. – Jonathan Grynspan Nov 01 '11 at 12:34
  • 1
    You do not have to know where retain and release statements would be inserted in order to write ARC code (that would negate the whole point of ARC). Instead, think in terms of object ownership and relationships. –  Jun 05 '12 at 16:33

3 Answers3

23

Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:

(gdb) info malloc-history 0x543216

Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.

See this article for more detailed instructions.

chown
  • 51,908
  • 16
  • 134
  • 170
2

ARC relies on the Apple standard/recommended naming practices. Check that you are not violating any of them.

Just for starters, if "Libraries" is an instance there are are naming issues.

zaph
  • 111,848
  • 21
  • 189
  • 228
  • As I mentioned above, I didn't see this naming convention rule. Can you post a link to where you found it? Thanks! – mbm29414 Oct 30 '11 at 19:52
  • See: [Coding Guidelines for Cocoa](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingMethods.html#//apple_ref/doc/uid/20001282-BCIGIJJF) – zaph Oct 30 '11 at 19:55
1

OK, so I feel a little bit silly, but I've got two production machines. On one of them, I had installed a copy of Xcode 4.2 beta alongside the final, production copy. I forgot to uninstall the beta copy and was using it to run my code. As soon as I cleared that up and ran my code against the final, released Xcode 4.2, all works fine again.

As I mentioned to Jonathan Grynspan above, I DO understand Obj-C memory management. For some reason, I was getting a retain/release/release (performed by ARC), and that bug is remedied in the final version.

Thanks for the help in tracking this down! At least I got a definitive answer to WHY the problem existed!

mbm29414
  • 11,558
  • 6
  • 56
  • 87