gbd shell malloc_history. Issue with [NSString stringWithFormat:]

Discussion in 'iOS Programming' started by l0uismustdie, Aug 16, 2010.

  1. l0uismustdie macrumors regular


    Nov 30, 2009
    Edinburgh, UK
    Hello. I am pretty new to Objective-C programming and am having some issues with memory management. I found a good debugging tool in the "shell malloc_history" command but am having some trouble deciphering the output. This is the output I am receiving:
    ALLOC 0xdd59a50-0xdd59a6f [size=32]: thread_a02c9500 |start | main | UIApplicationMain | GSEventRun | GSEventRunModal | CFRunLoopRunInMode | CFRunLoopRunSpecific | __CFRunLoopRun | __CFRunLoopDoSources0 | __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ | MultiplexerSource::perform() | URLConnectionClient::processEvents() | URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) | URLConnectionClient::_clientDidFinishLoading(URLConnectionClient::ClientConnectionEventQueue*) | _NSURLConnectionDidFinishLoading | -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] | -[URLRequest connectionDidFinishLoading:] | -[vmAppDelegate executeBoincBinary:] | -[virtual_machine_32 loadelf:] | +[NSString stringWithFormat:] | -[NSPlaceholderString initWithFormat:locale:arguments:] | _CFStringCreateWithFormatAndArgumentsAux | CFStringCreateMutable | _CFRuntimeCreateInstance | malloc_zone_malloc 
    This makes me believe there is a problem in my loadelf: function, particularly a line [NSString stringWithFormat:]. I've located this line (the only time I use [NSString stringWithFormat:] in this function and it reads:
    [memory setValue:[NSNumber numberWithInt:[filespace characterAtIndex:b]] forKey:[NSString stringWithFormat:@"%i", addr+b-offset]];
    My code is more often than not crashing with this error:
    2010-08-16 21:20:11.944 vm[16315:207] *** -[CFString length]: message sent to deallocated instance 0xe4efd40
    My questions are:
    Am I looking in the right place for this malloc issue?
    If so what is wrong with this line of code?? I have used this technique throughout my entire program and have had no issues.

    Thanks again for any help anyone can provide and if some more info is needed please let me know and I will post it as soon as possible.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    What are the types or classes of:

    Since the problem seems to be messaging a deallocated instance, you might want to try running with NSZombieEnabled.

    Example google result:

    If I had to guess, I'd guess characterAtIndex: is failing, because filespace is a dangling reference.

Share This Page