I have a property :
@property(nonatomic, assign)UIView *currentView; when I process the follow code, why it will break?
_currentView =nil; UIView * v1 = [[UIView alloc] initWithFrame:CGRectZero]; _currentView = v1; NSLog(@"_currentView %@", _currentView); NSLog(@"v1 %@", v1); [v1 release]; NSLog(@"_currentView %@", _currentView); ///break here. NSLog(@"v1 %@", v1); I think the _currentView and v1 both point to a same memory. When use v1 to realese the object, and use _currentView to print the object, it will crash. I can understand this.
But if the add follow line after v1 release and before print _currentView. I can`t understand the log.
v1 = nil; the code like follow
_currentView =nil; UIView * v1 = [[UIView alloc] initWithFrame:CGRectZero]; _currentView = v1; NSLog(@"_currentView %@", _currentView); NSLog(@"v1 %@", v1); [v1 release]; v1 = nil; NSLog(@"_currentView %@", _currentView); NSLog(@"v1 %@", v1); print result is :
> 2012-05-30 15:16:57.314 All[3068:15203] _currentView <UIView: 0x81ccbc0; frame = (0 0; 0 0); layer = <CALayer: 0xa07e5a0>> > 2012-05-30 15:16:57.798 All[3068:15203] v1 <UIView: 0x81ccbc0; frame = (0 0; 0 0); layer = <CALayer: 0xa07e5a0> > 2012-05-30 15:16:59.189 All[3068:15203] _currentView <UIView: 0x81ccbc0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; alpha = 0; layer = (null) > 2012-05-30 15:17:09.042 All[3068:15203] v1 (null) Why after invoke v1 release, and log _currentView, it will print
_currentView <UIView: 0x81ccbc0; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; alpha = 0; layer = (null)>