I have found a memory leak in my application which is a ARC converted application.
我在我的应用程序中发现了一个内存泄漏,这是一个ARC转换的应用程序。
Instrument shows that leak responsible library is libsystem_c.dylib
仪器显示泄漏负责库是libsystem_c.dylib
I am attaching the screen shot here..
我在这附加屏幕截图..
I have searched about the issue and i found the related posts in
我搜索了这个问题,我找到了相关的帖子
instruments-show-leak-in-main-m-xcode-4-3-1
仪器出现泄漏功能于主-M-xcode的-4-3-1
obj-c-memory-leak-of-malloc-48-bytes-in-strdup-framework
OBJ-C-内存泄漏的-的malloc-48字节合的strdup框架
Is it a bug in the iOS 5.1 framework?
这是iOS 5.1框架中的错误吗?
Any help on this is appreciated.
对此有任何帮助表示赞赏。
1 个解决方案
#1
1
EDIT:
编辑:
indeed, it seems there is some king of bug in iOS SDK 5.1 strdup (or related). See this thread from the developers forum.
事实上,似乎iOS SDK 5.1 strdup(或相关)中存在一些bug。从开发人员论坛中查看此主题。
it would be interesting if you can dig a bit into the Elements sample (which is the one that is said to reveal the bug) and see if you are using the same kind of functionality.
如果你可以挖掘一下Elements样本(据说是揭示bug的那个),看看你是否使用了同样的功能,那将会很有趣。
Here is a stack trace at the moment of the leak:
这是泄漏时的堆栈跟踪:
0 libsystem_c.dylib malloc
1 libsystem_c.dylib strdup
2 libnotify.dylib token_table_add
3 libnotify.dylib notify_register_mach_port
4 libnotify.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 ___UIGestureRecognizerUpdate_block_invoke_0541
13 UIKit _UIGestureRecognizerApplyBlocksToArray
14 UIKit _UIGestureRecognizerUpdate
15 UIKit _UIGestureRecognizerUpdateGesturesFromSendEvent
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_SOURCE0_PERFORM_FUNCTION__
22 CoreFoundation __CFRunLoopDoSources0
23 CoreFoundation __CFRunLoopRun
24 CoreFoundation CFRunLoopRunSpecific
25 CoreFoundation CFRunLoopRunInMode
26 GraphicsServices GSEventRunModal
27 UIKit UIApplicationMain
28 TheElements 0x300a
29 TheElements 0x2fc3
You can get your stack trace at the moment of the leak by choosing "Show Extended Detail" (or something similar) in the Instruments View menu.
通过在“仪器视图”菜单中选择“显示扩展详细信息”(或类似内容),可以在泄漏时获取堆栈跟踪。
OLD ANSWER:
老答案:
I suspect it is not.
我怀疑它不是。
In fact, what Instruments shows you as "responsible library" is the place where the actual malloc
call was effectively executed.
实际上,Instruments将您显示为“负责任的库”是实际malloc调用被有效执行的地方。
If you look at Instruments output, the culprit call is strdup
: there cannot possibly be a leak in strdup
.
如果你看看仪器输出,罪魁祸首就是strdup:strdup中不可能有泄漏。
It is more likely that you asked the OS (directly or indirectly) to duplicate some string, but then managed incorrectly the resulting copy of the string.
您更有可能要求操作系统(直接或间接)复制某些字符串,但随后错误地管理了字符串的结果副本。
Analyze the Extended Detail View which Instruments offer you, which shows the call stack at the moment the malloc
was called. This may help if there is a direct relationship between your code and the malloc
call itself. But even if the detailed view does not show such relationship, keep looking for the cause of the leak in your code.
分析Instruments为您提供的扩展详细信息视图,它显示调用malloc时的调用堆栈。如果您的代码与malloc调用本身之间存在直接关系,这可能会有所帮助。但即使详细视图没有显示这种关系,也要继续查找代码中泄漏的原因。
More in general, try to understand which part of your app is running when the leak is found (take into account the fact that leaks analysed at discrete times, e.g., every 10 seconds, so when you see the red bar appear, that means that the leak was produced during the last 10 seconds), and review all memory operations you do in the relevant classes.
更一般地,在发现泄漏时尝试了解应用程序的哪个部分正在运行(考虑到在离散时间分析泄漏的事实,例如,每10秒,所以当您看到红色条出现时,这意味着泄漏是在最后10秒内产生的,并检查您在相关课程中执行的所有记忆操作。
In my experience, it is pretty normal (100% of cases) that Instruments shows some part of the SDK as "responsible" for a leak, but at a deeper analysis the wrong code is on my part.
根据我的经验,仪器显示SDK的某些部分是“负责”泄漏是很正常的(100%的情况),但是在更深入的分析中,错误的代码就是我自己。
#1
1
EDIT:
编辑:
indeed, it seems there is some king of bug in iOS SDK 5.1 strdup (or related). See this thread from the developers forum.
事实上,似乎iOS SDK 5.1 strdup(或相关)中存在一些bug。从开发人员论坛中查看此主题。
it would be interesting if you can dig a bit into the Elements sample (which is the one that is said to reveal the bug) and see if you are using the same kind of functionality.
如果你可以挖掘一下Elements样本(据说是揭示bug的那个),看看你是否使用了同样的功能,那将会很有趣。
Here is a stack trace at the moment of the leak:
这是泄漏时的堆栈跟踪:
0 libsystem_c.dylib malloc
1 libsystem_c.dylib strdup
2 libnotify.dylib token_table_add
3 libnotify.dylib notify_register_mach_port
4 libnotify.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 ___UIGestureRecognizerUpdate_block_invoke_0541
13 UIKit _UIGestureRecognizerApplyBlocksToArray
14 UIKit _UIGestureRecognizerUpdate
15 UIKit _UIGestureRecognizerUpdateGesturesFromSendEvent
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_SOURCE0_PERFORM_FUNCTION__
22 CoreFoundation __CFRunLoopDoSources0
23 CoreFoundation __CFRunLoopRun
24 CoreFoundation CFRunLoopRunSpecific
25 CoreFoundation CFRunLoopRunInMode
26 GraphicsServices GSEventRunModal
27 UIKit UIApplicationMain
28 TheElements 0x300a
29 TheElements 0x2fc3
You can get your stack trace at the moment of the leak by choosing "Show Extended Detail" (or something similar) in the Instruments View menu.
通过在“仪器视图”菜单中选择“显示扩展详细信息”(或类似内容),可以在泄漏时获取堆栈跟踪。
OLD ANSWER:
老答案:
I suspect it is not.
我怀疑它不是。
In fact, what Instruments shows you as "responsible library" is the place where the actual malloc
call was effectively executed.
实际上,Instruments将您显示为“负责任的库”是实际malloc调用被有效执行的地方。
If you look at Instruments output, the culprit call is strdup
: there cannot possibly be a leak in strdup
.
如果你看看仪器输出,罪魁祸首就是strdup:strdup中不可能有泄漏。
It is more likely that you asked the OS (directly or indirectly) to duplicate some string, but then managed incorrectly the resulting copy of the string.
您更有可能要求操作系统(直接或间接)复制某些字符串,但随后错误地管理了字符串的结果副本。
Analyze the Extended Detail View which Instruments offer you, which shows the call stack at the moment the malloc
was called. This may help if there is a direct relationship between your code and the malloc
call itself. But even if the detailed view does not show such relationship, keep looking for the cause of the leak in your code.
分析Instruments为您提供的扩展详细信息视图,它显示调用malloc时的调用堆栈。如果您的代码与malloc调用本身之间存在直接关系,这可能会有所帮助。但即使详细视图没有显示这种关系,也要继续查找代码中泄漏的原因。
More in general, try to understand which part of your app is running when the leak is found (take into account the fact that leaks analysed at discrete times, e.g., every 10 seconds, so when you see the red bar appear, that means that the leak was produced during the last 10 seconds), and review all memory operations you do in the relevant classes.
更一般地,在发现泄漏时尝试了解应用程序的哪个部分正在运行(考虑到在离散时间分析泄漏的事实,例如,每10秒,所以当您看到红色条出现时,这意味着泄漏是在最后10秒内产生的,并检查您在相关课程中执行的所有记忆操作。
In my experience, it is pretty normal (100% of cases) that Instruments shows some part of the SDK as "responsible" for a leak, but at a deeper analysis the wrong code is on my part.
根据我的经验,仪器显示SDK的某些部分是“负责”泄漏是很正常的(100%的情况),但是在更深入的分析中,错误的代码就是我自己。