Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 了解malloc_历史转储_Objective C_Ios_Malloc History - Fatal编程技术网

Objective c 了解malloc_历史转储

Objective c 了解malloc_历史转储,objective-c,ios,malloc-history,Objective C,Ios,Malloc History,如果您曾经问过如何在objective-c中调试发布/分配问题,您将遇到以下环境设置,这些设置有助于跟踪问题: NSZombieEnabled-在发布后保留abject,以便您可以获取指针等 MallocStackLogging-保留对象历史记录供以后参考 NSDebugEnabled 在“可执行文件”(在组树中找到)信息的“参数”选项卡的“环境”部分,将所有这些设置为YES 所以,我得到了这个控制台输出 MyApp[4413:40b]-[CALayer retainCount]:发送到的

如果您曾经问过如何在objective-c中调试发布/分配问题,您将遇到以下环境设置,这些设置有助于跟踪问题:

  • NSZombieEnabled
    -在发布后保留abject,以便您可以获取指针等
  • MallocStackLogging
    -保留对象历史记录供以后参考
  • NSDebugEnabled
在“可执行文件”(在组树中找到)信息的“参数”选项卡的“环境”部分,将所有这些设置为
YES


所以,我得到了这个控制台输出

MyApp[4413:40b]-[CALayer retainCount]:发送到的消息 解除分配的实例0x4dbb170

然后打开终端,同时调试器已转发中断并键入:

malloc_历史4413 0x4DB170

然后,我得到一个大的文本转储,据我所知,重要的是:

一,

二,

三,

但我不明白的是,如果历史记录是ALLOC、FREE、ALLOC,那么为什么错误表明它已发布(net+1 ALLOC)?

还是我对转储的理解有误?


编辑(新运行=不同的对象指针):

使用仪器检测僵尸:

为什么以及如何将保留计数从1跳到-1

查看僵尸的回溯,看起来保留计数是由:Quartz通过release\u root\u(如果未使用)调用的



编辑:已解决-我正在从super中删除一个视图,然后将其释放。只需释放它即可修复。

我不是专家,但如果您查看第3块中的第一行:

ALLOC0x4DB170-0x4DB19F[大小=48]


在其他两个输出中,分配并释放了0x4dbb160-0x4dbb171处大小为18的内存块。我假设旧对象已被释放,并且有一个新对象驻留在此内存地址。因此,0x…b160处的旧实例不再有效。

@Kay是正确的;malloc历史记录显示指定地址的两个分配;一个已经被分配和释放,另一个仍在使用中

您需要的是对已发布的
CALayer
上的
retainCount
调用的回溯。因为您启用了僵尸检测,以及其他内存调试功能,所以解除分配可能根本没有发生&也不会发生

将malloc历史记录与僵尸检测相混合会显著改变运行时行为

我建议用仪器检测僵尸。希望这能找出确切的问题

如果没有,那么在发送僵尸消息时,可以设置一个断点来中断。设置断点并查看停止的位置


好的——CoreAnimation将保留计数用于内部目的(系统框架可以解决这个问题,尽管它很脆弱)

我认为-1是一条红鲱鱼;僵尸很可能返回0xFF…FFFF作为保留计数,并且在工具中呈现为-1

次优猜测;因为这是在计时器中发生的,所以过度释放可能是在动画期间发生的。CoreAnimation层应正确处理此问题。代码中视图或动画层容器的过度释放导致层过早消失

你试过“构建和分析”吗?很可能它会发现某个地方的风景管理不善

在任何情况下,作为一个实验,试着多保留一段时间,看看这是否能让这个问题停止。如果有,那至少是一个线索

(或者它可能是系统框架中的一个缺陷……也许……但值得怀疑。)

最后,到底是谁在呼叫
retainCount
?!?!?在CoreAnimation的情况下,
retainCount
可能在内部用作实现细节


如果是您的代码,那么僵尸调用的位置应该非常明显。

我认为大小可能是一个指标。一个对象的id是起始地址,所以块3中分配的对象是导致我出现问题的对象(因为它的起始地址是控制台中报告的对象)。我不明白的是,它在这里清楚地显示了它的分配。但是这个错误表明它已经被释放了……你是对的,我希望malloc历史记录中有第四个条目表明b170是免费的。可能指向内存本身的指针已损坏?您是否在运行菜单中启用了“停止Obj-C异常”?有一个网站是我不久前加入书签的。也许你会在那里找到一些提示。EXC_BAD_访问不是例外,这是一次崩溃。停止于Obj-C异常不会停止于此(但调试器始终会)。感谢您的帮助,跟踪了问题:我正在从super中删除一个具有子视图和(大)子层的视图,然后在此之后释放该视图。相反,现在我只是释放。自从我将应用程序升级到4.2(ipad)后,它才开始出现——这是我学到的教训。再次感谢。
ALLOC 0x4dbb160-0x4dbb171 [size=18]:
thread_a0375540 |start | main |
UIApplicationMain | GSEventRun |
GSEventRunModal | CFRunLoopRunInMode |
CFRunLoopRunSpecific | __CFRunLoopRun
| __CFRunLoopDoTimer |
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
| __NSFireDelayedPerform |
-[todoListViewController drillDocumentMenu:] |
-[documentListViewController drillIntoDocumentWithToDoRecord:] |
-[documentViewController OpenTodoDocument:OfType:WithPath:] |
-[documentViewController OpenDocumentOfType:WithPath:] |
-[documentViewController managePDFDocumentWithPath:] |
-[PDFDocument loadPDFDocumentWithPath:andTitle:] |
-[PDFDocument getMetaData] | CGPDFDictionaryApplyFunction |
ListDictionaryObjects(char const*,
CGPDFObject*, void*) | NSLog | NSLogv
| _CFLogvEx | __CFLogCString |
asl_send | _asl_send_level_message |
asl_set_query | strdup | malloc |
malloc_zone_malloc 
FREE  0x4dbb160-0x4dbb171 [size=18]:
thread_a0375540 |start | main |
UIApplicationMain | GSEventRun |
GSEventRunModal | CFRunLoopRunInMode |
CFRunLoopRunSpecific | __CFRunLoopRun
| __CFRunLoopDoTimer |
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
| __NSFireDelayedPerform |
-[todoListViewController drillDocumentMenu:] |
-[documentListViewController drillIntoDocumentWithToDoRecord:] |
-[documentViewController OpenTodoDocument:OfType:WithPath:] |
-[documentViewController OpenDocumentOfType:WithPath:] |
-[documentViewController managePDFDocumentWithPath:] |
-[PDFDocument loadPDFDocumentWithPath:andTitle:] |
-[PDFDocument getMetaData] | CGPDFDictionaryApplyFunction |
ListDictionaryObjects(char const*,
CGPDFObject*, void*) | NSLog | NSLogv
| _CFLogvEx | __CFLogCString |
asl_send | _asl_send_level_message |
asl_free | free
ALLOC 0x4dbb170-0x4dbb19f [size=48]:
thread_a0375540 |start | main |
UIApplicationMain | GSEventRun |
GSEventRunModal | CFRunLoopRunInMode |
CFRunLoopRunSpecific | __CFRunLoopRun
| __CFRunLoopDoTimer |
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
| __NSFireDelayedPerform |
-[todoListViewController drillDocumentMenu:] |
-[documentListViewController drillIntoDocumentWithToDoRecord:] |
-[documentViewController OpenTodoDocument:OfType:WithPath:] |
-[documentViewController OpenDocumentOfType:WithPath:] |
-[documentViewController managePDFDocumentWithPath:] |
-[ScrollViewWithPagingViewController init] | -[UIView init] |
-[UIScrollView initWithFrame:] | -[UIView initWithFrame:] | UIViewCommonInitWithFrame | -[UIView
_createLayerWithFrame:] | +[NSObject(NSObject) alloc] | +[NSObject(NSObject) allocWithZone:] | class_createInstance |
_internal_class_createInstanceFromZone | calloc | malloc_zone_calloc