Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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/107.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中的内存管理,属性返回一个带有+;1保留计数,UIGraphicsBeginImageContextWithOptions_Objective C_Ios_Cocoa Touch_Memory Management - Fatal编程技术网

Objective-C中的内存管理,属性返回一个带有+;1保留计数,UIGraphicsBeginImageContextWithOptions

Objective-C中的内存管理,属性返回一个带有+;1保留计数,UIGraphicsBeginImageContextWithOptions,objective-c,ios,cocoa-touch,memory-management,Objective C,Ios,Cocoa Touch,Memory Management,我运行了分析器,但我不确定内存管理的一些东西是如何工作的。我有一个属性(它没有自定义setter或getter): 之后我会尝试使用它: if ([[MyClass sharedDelegate].myArray containsObject:"test"]) 它表示“属性返回的Objective-C对象的保留计数为+1” 其中sharedelegate定义为: +(MyApp*)sharedDelegate { return (MyApp*)[[UIApplication share

我运行了分析器,但我不确定内存管理的一些东西是如何工作的。我有一个属性(它没有自定义setter或getter):

之后我会尝试使用它:

if ([[MyClass sharedDelegate].myArray containsObject:"test"])
它表示“属性返回的Objective-C对象的保留计数为+1”

其中
sharedelegate
定义为:

+(MyApp*)sharedDelegate
{
    return (MyApp*)[[UIApplication sharedApplication] delegate];
}
我不明白这一点,因为我看不到保留在哪里?我认为以这种方式使用属性就是使用getter方法,它只返回
myArray
的值。那么内存泄漏在哪里呢

然后它指向

UIGraphicsBeginImagecontextWithOptions(container.bounds.size, YES, 1.0);
对象泄漏:分配的对象稍后在此执行路径中未被引用,保留计数为+1


我也不明白这一点,或者这与第一次内存泄漏有什么关系。它们似乎不相关。

您已将属性标记为返回保留引用。

myArray的getter是什么@合成,还是定制

我认为错误也可能出现在sharedDelegate中。返回单身时不要保留


第二个似乎无关。可能您没有调用
UIGraphicsEndImageContext
。如果您在其他函数中调用它,这可能没问题。编译器期望在同一个函数中调用这两个函数的正常模式,但这不是必需的。

retain表示set时保留,而不是get时保留。我添加了sharedDelegate方法以帮助缩小问题范围,因为我仍然看不到错误。谢谢
UIGraphicsBeginImagecontextWithOptions(container.bounds.size, YES, 1.0);