【问题标题】:Instruments show leak in main.m (Xcode 4.3.1)仪器在 main.m (Xcode 4.3.1) 中显示泄漏
【发布时间】:2012-04-03 05:13:03
【问题描述】:

我正在使用 ARC 开发应用 在仪器中对我的应用程序进行内存泄漏分析时,它会在以下函数中显示泄漏:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])

{
    @autoreleasepool { 
       return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

这是否表明我的代码中的其他地方存在问题?

这是堆栈跟踪

   0 libsystem_c.dylib malloc
   1 libsystem_c.dylib strdup
   2 libnotify_sim.dylib token_table_add
   3 libnotify_sim.dylib notify_register_mach_port
   4 libnotify_sim.dylib notify_register_dispatch
   5 CoreFoundation _CFXNotificationRegisterObserver
   6 CoreFoundation CFNotificationCenterAddObserver
   7 UIKit -[UIScrollView(Static) _startTimer:]
   8 UIKit -[UIScrollView _endPanWithEvent:]
   9 UIKit -[UIScrollView handlePan:]
  10 UIKit _UIGestureRecognizerSendActions
  11 UIKit -[UIGestureRecognizer _updateGestureWithEvent:]
  12 UIKit -[UIGestureRecognizer _delayedUpdateGesture]
  13 UIKit ___UIGestureRecognizerUpdate_block_invoke_0541



14 UIKit _UIGestureRecognizerApplyBlocksToArray
  15 UIKit _UIGestureRecognizerUpdate
  16 UIKit -[UIWindow _sendGesturesForEvent:]
  17 UIKit -[UIWindow sendEvent:]
  18 UIKit -[UIApplication sendEvent:]
  19 UIKit _UIApplicationHandleEvent
  20 GraphicsServices PurpleEventCallback
  21 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
  22 CoreFoundation __CFRunLoopDoSource1
  23 CoreFoundation __CFRunLoopRun
  24 CoreFoundation CFRunLoopRunSpecific
  25 CoreFoundation CFRunLoopRunInMode
  26 GraphicsServices GSEventRunModal
  27 GraphicsServices GSEventRun
  28 UIKit UIApplicationMain
  29 MyProject/main.m:16
  30 MyProject start

【问题讨论】:

  • 您有任何特定的日志和错误代码吗?由于您没有自己编写此函数,因此问题出在您自己的代码中 =)
  • 仪器中的这个泄漏条目有帮助吗?在我的应用程序运行两分钟后,我得到了大约 10 个这样的条目:泄漏的对象:Malloc 48 字节,负责的库:libsystem_c.dylib 负责的框架:strdup。
  • 您应该能够单击此 malloc 块的地址并从那里获取堆栈跟踪,这应该可以帮助您找出它的来源。但老实说 - 10x 48 字节的泄漏不是最终世界,如果它停留在这个;)
  • 感谢您的回复。我已经用堆栈跟踪更新了我的问题,以防你想看看。我没有足够的经验来理解堆栈跟踪中的泄漏位置
  • 我现在也离开了我的域 - 但我认为有了这些额外的信息,其他人可能能够帮助你:)

标签: ios memory-leaks instruments


【解决方案1】:

这似乎是iOS 5.1框架中的一个bug: https://devforums.apple.com/message/630695

【讨论】:

    【解决方案2】:

    我在使用 ARC 时遇到了同样的问题,这是由视图控制器中的 dealloc 函数引起的。通过使用 dealloc 函数(在我的情况下没有做任何事情),可能不会调用默认行为。尝试注释掉所有的 dealloc 实例,这应该可以解决您的问题。

    【讨论】:

    • 我将 FMDatabase 用于调用了 super dealloc 的 sqlite。我已经评论了 super dealloc,但仪器仍然在同一个地方显示泄漏。我的项目中没有更多的 dealloc
    【解决方案3】:

    您的 main.m 看起来与我见过的其他文件不同。你是这样格式化的还是自动这样格式化的?这是我的一个 ARC 应用程序的示例。

    int main(int argc, char *argv[]) {
    
        @autoreleasepool {
            int retVal = UIApplicationMain(argc, argv, nil, nil);
            return retVal;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-05
      • 2011-05-31
      • 2012-05-07
      • 2012-07-07
      • 1970-01-01
      • 2020-08-01
      • 2017-10-09
      • 2011-10-04
      相关资源
      最近更新 更多