Tôi cần kiểm tra xem tôi đã phát hành biến trong mục tiêu-c chưa. Tôi cố gắng kiểm tra nếu nó thay đổi để null:Làm cách nào để kiểm tra xem một đối tượng có được phát hành không?
//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");
Kết quả là:
Build View Value (pointer): Null
Build View Value (pointer): Not Null
Build View Value (pointer): Not Null
Có cách nào dễ dàng hơn để kiểm tra xem nó được deallocated?
gì bạn dường như được hỏi không phải là nếu đối tượng đã được phát hành, nhưng đúng hơn là nếu nó đã được deallocated. – PengOne
có thể trùng lặp của [Làm thế nào để xác định xem tôi có một con trỏ để phát hành đối tượng?] (Http://stackoverflow.com/questions/12280799/how-to-determine-if-i-have-a-pointer-to- phát hành -object) – OrangeDog