views:

794

answers:

2

I'm developing a Cocoa app, and every so often when running my app in Xcode I get the following sorts of messages in the debugging console:

<My app name>(952,0xb0103000) malloc: free_garbage: garbage ptr = 0x107b2f0, has non-zero refcount = 1

I turned on MallocStackLogging and NSZombieEnabled and did a malloc_history on a couple of these addresses and got traces along the lines of that quoted at the bottom.

The common thread seems to be references to NSPopupButtonCell in all the blocks with the error.

My guess is that it's do to something being CFRetained somewhere but not released or made garbage collectable.

A) Is this more likely to be a programming error on my part or something in the framework that hasn't been properly updated for the GC yet?

B) What are the consequences of the issue provoking this message, if any? i.e. Do I need to pay attention to this message or can I just ignore it?

Call [2] [arg=48]: thread_a003d720 |start | main | NSApplicationMain | -[NSApplication run] | -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] | _DPSNextEvent | BlockUntilNextEventMatchingListInMode | ReceiveNextEventCommon | RunCurrentEventLoopInMode | CFRunLoopRunInMode | CFRunLoopRunSpecific | __CFRunLoopDoObservers | _handleWindowNeedsDisplay | -[NSWindow displayIfNeeded] | -[NSView displayIfNeeded] | -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] | -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] | -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] | -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] | -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] | -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] | -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] | -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] | -[NSView _drawRect:clip:] | -[NSControl drawRect:] | -[NSMenuItemCell drawWithFrame:inView:] | -[NSPopUpButtonCell _drawIndicatorWithFrame:inView:] | -[NSPopUpButtonCell _indicatorFrameForCellFrame:inView:] | -[NSPopUpButtonCell _indicatorFrameForCellFrame:isFlipped:] | -[NSPopUpButtonCell _defaultIndicatorImage] | -[NSPopUpButtonCell _coreUIDefaultIndicatorImage] | +[NSImage imageNamed:] | +[NSImage _coreUIImageWithName:] | +[NSImage coreUIImageWithBaseName:state:backgroundStyle:] | -[NSCoreUIImageRep imageWithoutEffectsRect] | SizeForImageOptions | CUICopyMeasurements | CUIRenderer::CopyMeasurements(CGRect, CGContext, __CFDictionary const*, __CFArray const*) | CUIRenderer::CopyImageMeasurements(long, CUIContext const*, __CFArray const*, __CFDictionary*) | CreateImageSourceFromDisk(long, CUIContext const*, long*, unsigned char*) | CUISharedArtReader::CreateImageSource(long) | CGImageSourceCreateWithDataProvider | CGImageReadCreateWithProvider | CGImageReadCreateWithData | _CGImageReadCreate | _CFRuntimeCreateInstance | CFAllocatorAllocate | auto_zone_allocate_object Call [4] [arg=0]: thread_b0103000 |thread_start | _pthread_start | auto_collection_thread(void*) | auto_collect_with_mode(Auto::Zone*, unsigned int) | auto_collect_internal(Auto::Zone*, int)

A: 

I see this all the time with Xcode. It is a memory management problem in Xcode itself, and nothing at all to do with your program.

If the errors were related to your program, they would show up in the debugging window (the one that shows up when you press shift-command-r) as well as in the system console.

Those Xcode malloc messages come up only in the system console, so they are not your problem.

Now, this issue of Apple releasing an IDE that dumps tonnes of memory error logs into the system console? That might be something to worry about :)

e.James
These are coming up directly in the debugging window, prefaced my my appname rather than Xcode (the way the ones in the system console you're talking about do).I'll edit the question to make that more clear.
Lawrence Johnston
In that case, it is definitely your program that throws them. I haven't used the GC, so I'm afraid I won't be of much help with the debugging. Good luck!
e.James
+2  A: 

It's actually in a lower-level framework used by Xcode, and any garbage-collected application that uses NSImage will also generate this same (innocuous but annoying) message.

One way to silence these is here: http://0xced.blogspot.com/2008/09/quietxcode.html

cdespinosa
That's exactly what I needed to know, and that app looks looks to be a good way to get rid of the messages. Thanks!
Lawrence Johnston
Just a note that QuietXcode seems to only quiet the Xcode originated non-zero retain count messages, not the ones from my app.Still well worth installing, though.
Lawrence Johnston