a
是 的一个实例NSString
。我想如果我在释放它后打印一个字符串,它会使应用程序崩溃。相反,它返回了分配给它的正确值。我的问题是,即使在释放对象之后,我们还能获得它的值吗?如果不是,为什么我能够看到 的值a
,即使在它被释放之后?
。H
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
NSString *a;
}
@end
.m
- (void)viewDidLoad
{
[super viewDidLoad];
a=[[NSString alloc]initWithString:@"abc"];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"String %@",a);
[a release];
NSLog(@"release %@",a);
[a retain];
NSLog(@"retain %@",a);
}
输出:-
2012-08-24 14:15:49.501 a[1176:f803] string abc
2012-08-24 14:15:53.404 a[1176:f803] release abc
2012-08-24 14:15:55.325 a[1176:f803] retain abc