【发布时间】: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