【发布时间】:2011-10-17 18:17:36
【问题描述】:
我需要能够检查我是否已经在 Objective-c 中释放了一个变量。我尝试检查它是否更改为null:
//Checks if buildview is null and returns respective output
if(BuildView == NULL)
NSLog(@"Build View Value (pointer): Null");
else
NSLog(@"Build View Value (pointer): Not Null");
//allocates memory and initalizes value
BuildView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
//Checks if buildview is null and returns respective output again
if(BuildView == NULL)
NSLog(@"Build View Value (pointer): Null");
else
NSLog(@"Build View Value (pointer): Not Null");
//Releases the view
[BuildView release];
//Checks if buildview is null and returns respective output again
if(BuildView == NULL)
NSLog(@"Build View Value (pointer): Null");
else
NSLog(@"Build View Value (pointer): Not Null");
结果是:
Build View Value (pointer): Null
Build View Value (pointer): Not Null
Build View Value (pointer): Not Null
有没有更简单的方法来检查它是否被释放?
【问题讨论】:
-
您似乎要问的不是对象是否已被释放,而是对象是否已被释放。
标签: objective-c memory-management null