crashing in device, not in simulator

Discussion in 'Mac Programming' started by sujithkrishnan, Jun 16, 2008.

  1. sujithkrishnan macrumors 6502

    May 9, 2008
    Hi all..

    urgent hep required....

    My iPhone app is parsing four xmls in an URL one by one, with same XMLReader Class object...
    My app works fine in simulator, but crashing in device...

    However in device, it will work in debug mode, not on direct app-start..

    This is the crash log... Being a beginner am not getting whats wrong with code..
    Version:         ??? (???)
    Code Type:       ARM (Native)
    Parent Process:  launchd [1]
    Date/Time:       2008-06-16 19:05:56.381 +0530
    OS Version:      iPhone OS 2.0 (5A331)
    Report Version:  103
    Exception Type:  00000020
    Exception Codes: 0x8badf00d
    Highlighted Thread:  0
    Application Specific Information:
    Failed to launch
    Thread 0:
    0   CoreFoundation                	0x30233796 CFStringGetCStringPtr + 102
    1   Foundation                    	0x30674a08 -[NSCFString isEqualToString:] + 84
    2   digbyWithXML                  	0x00009172 0x1000 + 33138
    3   Foundation                    	0x306cf31c _endElementNs + 436
    4   libxml2.2.dylib               	0x324e9514 0x324c0000 + 169236
    5   libxml2.2.dylib               	0x324cac14 0x324c0000 + 44052
    6   Foundation                    	0x306ce91e -[NSXMLParser parse] + 178
    7   digbyWithXML                  	0x00007d56 0x1000 + 27990
    8   digbyWithXML                  	0x00003950 0x1000 + 10576
    9   UIKit                         	0x30a5df08 -[UIApplication performInitializationWithURL:asPanel:] + 160
    10  UIKit                         	0x30a664ec -[UIApplication _runWithURL:] + 424
    11  Foundation                    	0x3069af60 __NSFireDelayedPerform + 452
    12  CoreFoundation                	0x3025bfec CFRunLoopRunSpecific + 2642
    13  CoreFoundation                	0x3025b584 CFRunLoopRunInMode + 44
    14  GraphicsServices              	0x316998e4 GSEventRunModal + 268
    15  UIKit                         	0x30a5e4a0 -[UIApplication _run] + 404
    16  UIKit                         	0x30a67374 UIApplicationMain + 1064
    17  digbyWithXML                  	0x000020be 0x1000 + 4286
    18  digbyWithXML                  	0x0000202c 0x1000 + 4140
    Thread 1:
    0   libSystem.B.dylib             	0x31446fd8 mach_msg_trap + 20
    1   libSystem.B.dylib             	0x314440a4 mach_msg + 60
    2   CoreFoundation                	0x3025b9ac CFRunLoopRunSpecific + 1042
    3   CoreFoundation                	0x3025b584 CFRunLoopRunInMode + 44
    4   WebCore                       	0x32b1a144 RunWebThread + 340
    5   libSystem.B.dylib             	0x3143ccba _pthread_body + 34
    Thread 2:
    0   libSystem.B.dylib             	0x31446fd8 mach_msg_trap + 20
    1   libSystem.B.dylib             	0x314440a4 mach_msg + 60
    2   GraphicsServices              	0x3169c3d0 EventReceiveThread + 504
    3   libSystem.B.dylib             	0x3143ccba _pthread_body + 34
    Thread 3:
    0   libSystem.B.dylib             	0x31446fd8 mach_msg_trap + 20
    1   libSystem.B.dylib             	0x314440a4 mach_msg + 60
    2   CoreFoundation                	0x3025b9ac CFRunLoopRunSpecific + 1042
    3   CoreFoundation                	0x3025b584 CFRunLoopRunInMode + 44
    4   Foundation                    	0x306ae3c6 +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 160
    5   Foundation                    	0x306761ea -[NSThread main] + 42
    6   Foundation                    	0x306760b8 __NSThread__main__ + 828
    7   libSystem.B.dylib             	0x3143ccba _pthread_body + 34
    Thread 4:
    0   libSystem.B.dylib             	0x313f85c8 __select + 20
    1   CoreFoundation                	0x30284c36 __CFSocketManager + 330
    2   libSystem.B.dylib             	0x3143ccba _pthread_body + 34
    Unknown thread crashed with unknown flavor: 5, state_count: 1
    Binary Images:
        0x1000 -     0xbfff +digbyWithXML ??? (???) <ac50a7095474ecdd1b99f4b08a81fa53> /var/mobile/Applications/BF3703A9-0E63-408E-BDE2-6F27C15CD856/
       0x2c000 -    0x2dfff ??? (???) <2917a1749c9c6bec548103172c27fb17> /usr/lib/info/
    0x2fe00000 - 0x2fe22fff  dyld ??? (???) <375e18175c2a039e95015c2bfe9d4227> /usr/lib/dyld
    0x30000000 - 0x30008fff  libgcc_s.1.dylib ??? (???) <bca92cc8051e73cdae6556e773a6784b> /usr/lib/libgcc_s.1.dylib
    0x3000c000 - 0x30079fff  libstdc++.6.dylib ??? (???) <eca236ef715a7f02b4d218057458bd82> /usr/lib/libstdc++.6.dylib
    0x300bb000 - 0x3019dfff  libobjc.A.dylib ??? (???) <38b26887da8d0c97a4ba98f465b232e4> /usr/lib/libobjc.A.dylib
    0x301eb000 - 0x301f2fff  libbsm.dylib ??? (???) <286a5bdb93717459c1174ffd2509ee24> /usr/lib/libbsm.dylib
    0x301f6000 - 0x30204fff  libz.1.dylib ??? (???) <6b19797961133a49d30e01658915cd62> /usr/lib/libz.1.dylib
    0x30229000 - 0x302cffff  CoreFoundation ??? (???) <c8ff9ee15235d601ac3a6f3946422b18> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
    0x30393000 - 0x30422fff  libsqlite3.0.dylib ??? (???) <ac7f663b552362efe1d95d6a6a6238f4> /usr/lib/libsqlite3.0.dylib
    0x3066f000 - 0x30756fff  Foundation ??? (???) <5ee8238fabdcca3b6ff0de5af076d2db> /System/Library/Frameworks/Foundation.framework/Foundation
    0x3087b000 - 0x30885fff  CoreVideo ??? (???) <6b7a577f0de2d4e3c678552eb0e4de3a> /System/Library/PrivateFrameworks/CoreVideo.framework/CoreVideo
    0x30894000 - 0x308a1fff  AppSupport ??? (???) <178d7b53352ae5f2cdf093b2c86110e0> /System/Library/PrivateFrameworks/AppSupport.framework/AppSupport
    0x308ab000 - 0x308b0fff  liblockdown.dylib ??? (???) <56ba31f4b3aed939804cfac3ccc1d545> /usr/lib/liblockdown.dylib
    0x30a54000 - 0x30cbbfff  UIKit ??? (???) <fd1da22a3008dcc0c98bd2e163224814> /System/Library/Frameworks/UIKit.framework/UIKit
    0x30f30000 - 0x30fb1fff 1.5.1 (???) <9252dcb3383328a5aa6eb1c179d74e5a> /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
    0x30fce000 - 0x3117ffff 1.359.4 (???) <e869e24949965f7e1c4c30116ecb1853> /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics
    0x311ce000 - 0x31222fff  CFNetwork ??? (???) <c0fe487711e20cf0e629ce7917633bd2> /System/Library/Frameworks/CFNetwork.framework/CFNetwork
    0x3124f000 - 0x31284fff  OpenGLES ??? (???) <7f80d8232402398cd2821928cefe2056> /System/Library/Frameworks/OpenGLES.framework/OpenGLES
    0x31290000 - 0x31354fff  JavaScriptCore ??? (???) <6f9a13aa831b794cd83274f2bbadd5c0> /System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore
    0x313d5000 - 0x314fcfff  libSystem.B.dylib ??? (???) <8b46166ae0e58f099c1a44f601df3ea1> /usr/lib/libSystem.B.dylib
    0x3153c000 - 0x3164dfff  AudioToolbox ??? (???) <30da7f2c0b1463cabca4f261eaafe40c> /System/Library/Frameworks/AudioToolbox.framework/AudioToolbox
    0x31696000 - 0x316a0fff  GraphicsServices ??? (???) <5375726eedb6be5aff436831aa21e1d0> /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
    0x316b9000 - 0x316eefff  Security ??? (???) <2ff032807b06ee425e635586f5701f88> /System/Library/Frameworks/Security.framework/Security
    0x31707000 - 0x3173ffff  ImageIO ??? (???) <f6d5786cedfa791ec4e23d472c262300> /System/Library/PrivateFrameworks/ImageIO.framework/ImageIO
    0x31753000 - 0x31757fff  libGIF.dylib ??? (???) <1e995be458aef3b9fd6fd1ea6975dc09> /System/Library/PrivateFrameworks/ImageIO.framework/libGIF.dylib
    0x3175a000 - 0x31777fff  libJPEG.dylib ??? (???) <465a2cc1de9f14ce0158181102085722> /System/Library/PrivateFrameworks/ImageIO.framework/libJPEG.dylib
    0x3177d000 - 0x31796fff  libPng.dylib ??? (???) <d00dad1db3a4ed0e3bd756deb9994dc3> /System/Library/PrivateFrameworks/ImageIO.framework/libPng.dylib
    0x3179c000 - 0x317d9fff  libTIFF.dylib ??? (???) <b22b03f1b754ea2f9c3e8a5abad6c62e> /System/Library/PrivateFrameworks/ImageIO.framework/libTIFF.dylib
    0x318da000 - 0x318ddfff  IAP ??? (???) <773aa1e7624c070a5da019af19873862> /System/Library/PrivateFrameworks/IAP.framework/IAP
    0x31908000 - 0x31935fff  SystemConfiguration ??? (???) <1636e3e508539422ab6cf416f88aadd2> /System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration
    0x31a11000 - 0x31a80fff  CoreAudio ??? (???) <660fbe6dc5df42cea893b40541d5dfe7> /System/Library/Frameworks/CoreAudio.framework/CoreAudio
    0x31b97000 - 0x31b97fff  DataMigration ??? (???) <47d5c9a38099a935a42260ab559b5028> /System/Library/PrivateFrameworks/DataMigration.framework/DataMigration
    0x31b9a000 - 0x31bb3fff  AddressBook ??? (???) <216b3949854157269b6a9b7aa25db220> /System/Library/Frameworks/AddressBook.framework/AddressBook
    0x31c97000 - 0x31c9cfff  MBX2D ??? (???) <c414988f1d36291539d1d0ee90018551> /System/Library/PrivateFrameworks/MBX2D.framework/MBX2D
    0x31ca0000 - 0x31ca1fff  MBXConnect ??? (???) <8d4d0c982d338f68f5a7f87d3432e983> /System/Library/PrivateFrameworks/MBXConnect.framework/MBXConnect
    0x31e7f000 - 0x31efdfff  QuartzCore ??? (???) <4b658b6d8cbc16b624e9deb1c3501809> /System/Library/Frameworks/QuartzCore.framework/QuartzCore
    0x31f36000 - 0x31f38fff  CoreSurface ??? (???) <7389e8d045b5d923dbd49033ddaa303e> /System/Library/PrivateFrameworks/CoreSurface.framework/CoreSurface
    0x31f3d000 - 0x31f3efff  IOMobileFramebuffer ??? (???) <8eddd72e77dde8072ffac6c6284cfcff> /System/Library/PrivateFrameworks/IOMobileFramebuffer.framework/IOMobileFramebuffer
    0x321f5000 - 0x322dafff  libicucore.A.dylib ??? (???) <6d47a95e76d2e3768897f4823025352c> /usr/lib/libicucore.A.dylib
    0x324c0000 - 0x32591fff  libxml2.2.dylib ??? (???) <fe9a61b3d6a1e47ec5218e17a99b377b> /usr/lib/libxml2.2.dylib
    0x326a4000 - 0x32baafff  WebCore ??? (???) <0020cecdff5fb16e950364622113b24a> /System/Library/PrivateFrameworks/WebCore.framework/WebCore
    0x32dd5000 - 0x32e59fff  WebKit ??? (???) <b66008eee9eba5c783f8bea72ddf1385> /System/Library/PrivateFrameworks/WebKit.framework/WebKit
    0x331f3000 - 0x33231fff  libCGFreetype.A.dylib ??? (???) <aace293e19c5b981a9fe57dc66ac1f7f> /System/Library/Frameworks/CoreGraphics.framework/Resources/libCGFreetype.A.dylib
    0x33b24000 - 0x33b29fff  SpringBoardServices ??? (???) <8f73daab1df31005887da7fa448d4549> /System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices
    0x342ba000 - 0x342d7fff  libresolv.9.dylib ??? (???) <095142564d8c13c1f5208ec9ce6c2c25> /usr/lib/libresolv.9.dylib
    Even i think so many memory leaks are there...
    Beyond that , is there any critical info in this log???

  2. Sbrocket macrumors 65816


    Jun 3, 2007
    Couldn't tell you what's causing it, but those aren't memory leaks. Those are just binary resources in use at time of the crash.
  3. ScoobyMcDoo macrumors 65816

    Nov 26, 2007
    Austin, TX
    What you describe are classic symptoms of not initializing your variables, then using them uninitialized. Debug builds and simulators usually initialize all memory to zeros - normal builds usually do not.
  4. sujithkrishnan thread starter macrumors 6502

    May 9, 2008
    "release" and "assigning nil"


    if i am allocating and assigning nil, is it OK?

    I just want to know what is the best way to release an instance...

    I am from BReW, and there we do safe deallocation like this:

    (Code in OBJ-C syntax)
    (if [I]object[/I] !=nil)
       [I]object[/I] = nil;
       [[I]object[/I] release];
    Is it OK with Objective C also???
  5. eddietr macrumors 6502a

    Oct 29, 2006
    You may want to check the iPhone developer program agreement. My understanding is that until the SDK is final, we are not supposed to be discussing the iPhone SDK or posting crash logs.

    But this particular question is not about the iPhone really, it's about Obj-C in general. You cannot set an object pointer to nil and then try to release that object. If you think about it, you are sending the release message to nil. In other words, you are sending the message to no one and so nothing is being released when you do this.

    Also, why are you testing for nil before the release? Is this because you are afraid of over-releasing in this case? You do realize, I hope, that you must properly release objects that are not nil but still need to be released?
  6. Sbrocket macrumors 65816


    Jun 3, 2007
    It seems to be, from this snippet, that you need to read up on Cocoa memory management some. As eddietr said, all you'd be doing here is setting a non-nil object to nil and then sending it a message. Now, sending messages to nil is not a problem in Objective-C, but that's not going to release anything either.

    What exactly are you trying to do here? I don't get the point of this block of code, and it seems to me your fundamental notion of using the retain count method of memory management is screwy.
  7. sujithkrishnan thread starter macrumors 6502

    May 9, 2008

    My doubt is eventhough we release the instance, the retian count will deceremented, But i afraid that the memory is still get occupied...

    My thought is
    by releasing reference doesnt mean we are clearing the memory

    Thanks for the advice....
    I will read the memory management Guide in more detail....
  8. sujithkrishnan thread starter macrumors 6502

    May 9, 2008

    I found a statement in a material regarding Memroy Management
    I understood the thumb rule for alloc,copy,reatin etc....

    But i didnt get this staement.. Can anyone help in program terms...
    I mean a snippet kind of this statement...

    When you receive an object (as the result of a method call), it will normally remain valid until the end of your method and the object can be safely returned as a result of your method. If you need the object to live longer than this--for example, if you plan to store it in an instance variable--then you must either -retain or -copy the object.
  9. eddietr macrumors 6502a

    Oct 29, 2006
    That's exactly right. By decrementing the count, you are indicating that you do not need the object any more. But some other code may still need the object to exist.

    So you decrement the count and then if the count is zero as a result, then the runtime will call dealloc on that object and subsequently free the memory.

    So for example:

    1.) Create a String
    2.) Put the string in an array.
    3.) Release the string

    After step 3, the String will continue to exist and should continue to exist because the array is still maintaining a handle to it.
  10. cMacSW macrumors regular

    Mar 20, 2006
    There are alot of good suggestion regarding memory management that others have made... but back to your

    This line from the log is where I would start looking:

    [NSCFString isEqualToString:]

    if the second string is nil or if the 1st string pointer is an invalid address, which it could be if not initialized, then it would crash. If in simulate or debug mode the 1st string is set to nil then it likely wouldn't crash
  11. sujithkrishnan thread starter macrumors 6502

    May 9, 2008

    I am having two more doubt regarding my code...

    class1 *staticObject = [class1 getStaticObject];
    [B]//in a loop[/B]
    class2 *tempObject = [[class2 alloc] init];
    //assign some values to memebers of class2 
    [class1Object.class2ObjectArray addObject:tempObject];
    // in above static method i am allocating memory for class2ObjectArray also..
    [tempObject release];
    [B]//end of loop[/B]
    Is my this part of code is right with respect to memory management??
    did tempObject get fully deallocated??

    NSString *strObj = [[NSString alloc]init];
    [B]//in a loop[/B]
    strObj = [strObj stringByAppendingString:anotherValidString];
    [B]//end of loop[/B]
    [B]// assign strObj to mainString[/B] 
    [strObj release];
    I came to know that stringByAppendingString returns another string pointer, so how i can free the memory held by strObj previously, as now it contains the new string returned by the method..

    Or help me with some thumb rules to follow when deploying in device than in simulator...

  12. eddietr macrumors 6502a

    Oct 29, 2006
    You seem to have the right idea here. If you add an object to a collection, the collection will retain the object (assuming you are using one of the framework collections). So therefore you should release it here when you are done with it.

    But again, tempObject is not and should not be "fully deallocated" here. If it were fully deallocated here, then what would the array be holding onto?
    The only way you can release an object is by holding on to the pointer to it. If you overwrite the pointer, than you can't message the original NSObject.

    Again, we cannot discuss the particulars of the iPhone SDK on a public forum. Please refer to the agreement you signed.

    But we can discuss memory management in Obj-C. Your code will not run well in production on a Mac or anything else if you don't manage memory properly.
  13. MongoTheGeek macrumors 68040


    Sep 13, 2003
    Its not so much where you are as when you are.
    Obj-c has retain counts on all objects. It keeps track of how many things want the object kept alive. When you call retain you increase it by 1. When you call release you decrease it by 1. When you call autorelease you decrease it by 1, later. Autorelease is used to pass variables outside of your current method.

    Any method that begins with "alloc" or "new" or contains the word "copy" generates a retained object.

    In your case.

    NSString *strObj = [[[NSString alloc]init] autorelease];
    strObj = [strObj stringByAppendingString:anotherValidString];
    mainString = [strObj copy];  //make sure its retained.
    And since strObj was never retained by anything it goes away without leaking.

    Now. Just to muddy the waters. The iPhone uses Obj-C 2.0 with garbage collection. This means you can pretty much ignore all this and just say.

    NSString *strObj = [[NSString alloc]init];
    strObj = [strObj stringByAppendingString:anotherValidString];
    mainString = strObj;
    Look at the memory management help guides in XCode for more information.
  14. Sbrocket macrumors 65816


    Jun 3, 2007
    That is completely incorrect. There is no Garbage Collection on the iPhone (too much overhead for too little gain, on a desktop/laptop it doesn't matter as much), you must use memory management with retain/release/autorelease. The other features of Objective-C 2.0 are on the iPhone, however.

    sujithkrishnan: If you can get on and look for 'sgtblue52' when I'm on, I'd be happy to walk you through some of the particulars of memory management in a more one-on-one interactive way (cause I'm not about to write up a guide on it). Otherwise, I suggest picking up a copy of a book like Aaron Hillegass' "Cocoa Programming for Mac OS X" and reading the section there on memory management. Not only that, but the book contains many things (like sections on Foundation classes) that will help you on Cocoa Touch. Its a great book to read, even if you're doing iPhone development.
  15. sujithkrishnan thread starter macrumors 6502

    May 9, 2008
    Still i didnt get Why the stuff going fine in debugging mode in device, and not working in normal app startup?? (Something related to initialization??)

    Presently i am facing such a situation...

    I got a reply like app is crashing b/cause I am trying to release which are not supposed to release. So i tried with releases only after adding to NSArrays and NSDictionary. Still the same old story continuing....

    ThankYou 'SBRocket' n all for overwhelming support, being a beginner i am looking forward the help from ur part..

    Even i am having am XMLParser instance (a property) , i am trying to release it after each parsing, Then app crashing with EXEC_BAD_ACCESS

    I just got the device, and i developed almost the entire thing with simulator, where it worked fine, now i am in the middle of sea with such troubles...
  16. Sbrocket macrumors 65816


    Jun 3, 2007
  17. eddietr macrumors 6502a

    Oct 29, 2006
    Like others have said, running in a simulator will sometimes hide certain memory management bugs. The reason your code runs differently is probably because you still are not managing the memory properly.

    This is particularly true in Obj C where the runtime will happily send messages to a nil pointer all day long.

Share This Page