- #import<Foundation/Foundation.h>
- @interface Person : NSObject
- {NSString *_name;
- }
- @property(nonatomic,strong) NSString*name;
- + (id) sharedPerson;
- @end
- static Person *p;
- @implementation Person
- + (id) sharedPerson{
- if (p =! nil)
- {
- p =[[[self class] alloc] init];
- }
- return p;
- }
- @end
- int main()
- {
- Person *p1 =[Person sharedPerson];
- Person *p2 =[Person sharedPerson];
- NSLog(@"p1 is %p,p2 is %p",p1,p2);
- return 0;
- }
- P1和P2为什么指向不是同一空间,还有,我这个在ARC下有没有内存泄露,帮忙看看呐
复制代码 |