【问题标题】:Cocoa development: malloc: free_garbage: garbage ptr = 0x18a15e0, has non-zero refcount = 1 errorCocoa 开发:malloc:free_garbage:garbage ptr = 0x18a15e0, has non-zero refcount = 1 error
【发布时间】:2009-04-29 18:31:07
【问题描述】:

我正在开发一个 Cocoa 应用程序,在 Xcode 中运行我的应用程序时,我经常在调试控制台中收到以下类型的消息:

<My app name>(952,0xb0103000) malloc: free_garbage: 垃圾 ptr = 0x107b2f0, 非零引用计数 = 1

我打开了 MallocStackLogging 和 NSZombieEnabled 并在其中几个地址上做了 malloc_history 并得到了沿着底部引用的行的跟踪。

公共线程似乎是在所有出现错误的块中对 NSPopupButtonCell 的引用。

我的猜测是它对某处被 CFRetained 但未释放或使垃圾可收集的东西起作用。

A) 这更有可能是我的编程错误,还是框架中尚未针对 GC 正确更新的问题?

B) 引发此消息的问题的后果是什么(如果有)?即我需要注意这条消息还是可以忽略它?

调用 [2] [arg=48]:thread_a003d720 |开始 |主要 | NSApplicationMain | -[NSApplication 运行] | -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] | _DPSNextEvent | BlockUntilNextEventMatchingListInMode | ReceiveNextEventCommon | RunCurrentEventLoopInMode | CFRunLoopRunInMode | CFRunLoopRun 特定 | __CFRunLoopDoObservers | _handleWindowNeedsDisplay | -[NSWindow displayIfNeeded] | -[NSView 显示如果需要] | -[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 | CUI复制测量 | CUIRenderer::CopyMeasurements(CGRect, CGContext*,__CFDictionary 常量*, __CFArray 常量*) | CUIRenderer::CopyImageMeasurements(长, CUIContext 常量*,__CFArray 常量*, __CFDictionary*) | CreateImageSourceFromDisk(长, CUIContext const*、long*、无符号 字符*) | CUISharedArtReader::CreateImageSource(long) | CGImageSourceCreateWithDataProvider | CGImageReadCreateWithProvider | CGImageReadCreateWithData | _CGImageReadCreate | _CFRuntimeCreateInstance | CFAllocatorAllocate | auto_zone_allocate_object 调用 [4] [arg=0]:thread_b0103000 |thread_start | _pthread_start | auto_collection_thread(void*) | auto_collect_with_mode(Auto::Zone*, 无符号整数) | auto_collect_internal(Auto::Zone*, 整数)

【问题讨论】:

    标签: cocoa xcode memory-leaks garbage-collection


    【解决方案1】:

    它实际上位于 Xcode 使用的较低级别的框架中,任何使用 NSImage 的垃圾收集应用程序也会生成同样的(无害但烦人的)消息。

    让这些静音的一种方法是:http://0xced.blogspot.com/2008/09/quietxcode.html

    【讨论】:

    • 这正是我需要知道的,而且该应用看起来是摆脱消息的好方法。谢谢!
    • 请注意,QuietXcode 似乎只会让 Xcode 发起的非零保留计数消息安静下来,而不是来自我的应用程序的消息。不过,仍然值得安装。
    【解决方案2】:

    我经常在 Xcode 中看到这一点。这是 Xcode 本身的内存管理问题,与您的程序完全无关。

    如果错误与您的程序有关,它们会显示在调试窗口(按 shift-command-r 时显示的窗口)以及系统控制台中。

    那些 Xcode malloc 消息只出现在系统控制台中,所以它们不是你的问题。

    现在,本期 Apple 发布了将大量内存错误日志转储到系统控制台的 IDE? 可能是需要担心的事情:)

    【讨论】:

    • 这些将直接出现在调试窗口中,以我的应用程序名称而不是 Xcode 开头(您正在谈论的系统控制台中的方式)。我将编辑问题以使其更清楚。
    • 在这种情况下,肯定是你的程序抛出了它们。我没用过GC,恐怕对调试没有多大帮助。祝你好运!
    猜你喜欢
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多