Yash Yash - 25 days ago 17
Objective-C Question

Release on assign property

What happened in MRC when someone called release message on property declared as assign.

In .h file:

@property (assign) int count;


in .m viewDidLoad Method:

_count = 10;
NSLog(_count);
[_count release]; // According to me it may give EXC_BAD_ACCESS
NSLog(_count);


Just want to confirm because don't have that much old Xcode in which I can test MRC.

Answer

I am pretty sure it will give you a compiler error as int does not inherit from NSObject, you cannot call release on it.

Anyways if you consider a NSObject with weak property it wont crash immediately when you call release because the original owner of the object will have incremented the objects reference count to atleast 1. When the owner of the object will be deallocated is when the app will crash because it is will try to release the object as it is the owner, but the object was deallocted because a non-owner has wrongly reduced its reference count.

Comments