R – Cocoa development: malloc: free_garbage: garbage ptr = 0x18a15e0, has non-zero refcount = 1 error

cocoagarbage-collectionmemory-leaksxcode

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)

Best Answer

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

Related Topic