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
Objective c 在目标C++类中调试μ弱变量的不正确用法_Objective C_Objective C++ - Fatal编程技术网

Objective c 在目标C++类中调试μ弱变量的不正确用法

Objective c 在目标C++类中调试μ弱变量的不正确用法,objective-c,objective-c++,Objective C,Objective C++,我的Objective-C++类MyObjectiveCppClass中有以下-dealloc实现: - (void)dealloc { if (_my_iVar) { [_my_iVar doSomeSlowishCleanUp]; } } 每当调用此-dealloc方法时,我都会收到一系列警告,如: objc[1254]: __weak variable at 0x1662a38c8 holds 0x19c70f408 instead of 0x160abe000. Thi

我的Objective-C++类MyObjectiveCppClass中有以下-dealloc实现:

- (void)dealloc {
  if (_my_iVar) {
    [_my_iVar doSomeSlowishCleanUp];
  }
}
每当调用此-dealloc方法时,我都会收到一系列警告,如:

objc[1254]: __weak variable at 0x1662a38c8 holds 0x19c70f408 instead of 0x160abe000. This is probably incorrect use of objc_storeWeak() and objc_loadWeak(). Break on objc_weak_error to debug.
当我在objc_弱_错误上中断时,堆栈如下所示:

#0  0x0000000182395330 in objc_weak_error ()
#1  0x00000001823959d0 in weak_clear_no_lock ()
#2  0x000000018239f1e8 in objc_object::clearDeallocating_slow() ()
#3  0x000000018238e074 in objc_destructInstance ()
#4  0x0000000182d25fac in -[NSObject(NSObject) __dealloc_zombie] ()
----> #5    0x00000001000a6c30 in -[MyObjectiveCppClass .cxx_destruct]
#6  0x0000000182382b54 in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#7  0x000000018238e040 in objc_destructInstance ()
#8  0x0000000182d25fac in -[NSObject(NSObject) __dealloc_zombie] ()
---->    #9 0x00000001000a691c in -[MyObjectiveCppClass dealloc] 
#10 0x0000000100611bc4 in -[SomeViewB .cxx_destruct]
#11 0x0000000182382b54 in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#12 0x000000018238e040 in objc_destructInstance ()
#13 0x0000000182d25fac in -[NSObject(NSObject) __dealloc_zombie] ()
#14 0x0000000188233a90 in -[UIResponder dealloc] ()
#15 0x0000000187e78b08 in -[UIView dealloc] ()
#16 0x0000000187f60700 in -[UIScrollView dealloc] ()
#17 0x0000000182c049b4 in -[__NSArrayM dealloc] ()
#18 0x00000001006495cc in -[SomeViewA .cxx_destruct]

有人知道如何修复这些警告吗?

事实证明,“我的”iVar对象有一个“不安全的”未保留的自身引用,并将其传递给一些子对象,其中一个将其分配给弱局部变量。

事实证明,“我的”iVar对象有一个“不安全的”未保留的自身引用,并且将其传递给某些子对象,其中一个子对象将其分配给弱局部变量。

如果它可以帮助您,请执行以下步骤:

从类中删除ARC-fobjc ARC。要执行此操作,请转到项目设置->构建阶段->编译源代码。现在选择您的类并删除-fobjc弧。 现在构建它,如果您有任何自动释放,请从.m文件中的声明中删除它。假设你有:

UILabel *label = [[[UILabel alloc] initWithFrame:rect] autorelease];
请像这样做:

    UILabel *label = [[UILabel alloc] initWithFrame:rect];
不过,您可能会遇到以下问题:

Cannot synthesize weak property in file using manual reference counting.
不要为这个问题担心

如果没有ARC,请转至下一步

删除圆弧后,再次转到“项目设置”。转到生成设置并在手动保留版本中搜索弱引用。该值当前为空。是的。
现在清理、构建并运行。

如果它可以帮助您,请按照以下步骤操作:

从类中删除ARC-fobjc ARC。要执行此操作,请转到项目设置->构建阶段->编译源代码。现在选择您的类并删除-fobjc弧。 现在构建它,如果您有任何自动释放,请从.m文件中的声明中删除它。假设你有:

UILabel *label = [[[UILabel alloc] initWithFrame:rect] autorelease];
请像这样做:

    UILabel *label = [[UILabel alloc] initWithFrame:rect];
不过,您可能会遇到以下问题:

Cannot synthesize weak property in file using manual reference counting.
不要为这个问题担心

如果没有ARC,请转至下一步

删除圆弧后,再次转到“项目设置”。转到生成设置并在手动保留版本中搜索弱引用。该值当前为空。是的。
现在清理、构建并运行。

当时的解决方案是什么?我遇到了一个类似的问题,但是有一个第三方库。你知道解决方案是什么吗?!当时的解决办法是什么?我遇到了一个类似的问题,但是有一个第三方库。你知道解决方案是什么吗?!