内存管理4Aotorelease自动引用计数
2013-08-02 15:11
411 查看
Student.h:
#import <Foundation/Foundation.h>
@interface Student : NSObject
@property(nonatomic,unsigned)int age;
+(id)student;
+(id)initWithAge:(int)age;
@end
Student.m:
#import "Student.h"
@implementation Student
+(id)student{
return [[[Student alloc] init] autorelease];
}
+(id)initWithAge:(int)age{
Student *stu=[[[Student alloc] init] autorelease];
stu.age=age;
return stu;
}
-(void)dealloc{
NSLog(@"%@被销毁",self);
[super dealloc];
}
@end
main:
#import <Foundation/Foundation.h>
#import "Student.h"
int main(int argc, const char * argv[])
{
//@autoreleasepool代表自动创建一个自动释放池
@autoreleasepool {
Student * stu=[[Student alloc] init];
[stu autorelease];
Student * stu1=[[Student alloc] init];
[stu1 autorelease];
//快速创建Student对象
Student * stu3=[[Student student] autorelease];
}
// @autoreleasepool {
//
// Student * stu2=[[[Student alloc] init] autorelease];
//// [stu2 autorelease];
//
// }
return 0;
}
#import <Foundation/Foundation.h>
@interface Student : NSObject
@property(nonatomic,unsigned)int age;
+(id)student;
+(id)initWithAge:(int)age;
@end
Student.m:
#import "Student.h"
@implementation Student
+(id)student{
return [[[Student alloc] init] autorelease];
}
+(id)initWithAge:(int)age{
Student *stu=[[[Student alloc] init] autorelease];
stu.age=age;
return stu;
}
-(void)dealloc{
NSLog(@"%@被销毁",self);
[super dealloc];
}
@end
main:
#import <Foundation/Foundation.h>
#import "Student.h"
int main(int argc, const char * argv[])
{
//@autoreleasepool代表自动创建一个自动释放池
@autoreleasepool {
Student * stu=[[Student alloc] init];
[stu autorelease];
Student * stu1=[[Student alloc] init];
[stu1 autorelease];
//快速创建Student对象
Student * stu3=[[Student student] autorelease];
}
// @autoreleasepool {
//
// Student * stu2=[[[Student alloc] init] autorelease];
//// [stu2 autorelease];
//
// }
return 0;
}
相关文章推荐
- 内存管理4Aotorelease自动引用计数
- Cocos2d-x中的引用计数(Reference Count)和自动释放池(AutoReleasePool)
- OC基础15:内存管理和自动引用计数
- (20)Cocos2d-x中的引用计数(Reference Count)和自动释放池(AutoReleasePool)
- [Cocos2D-X官方文档]:Cocos2d-x中的引用计数(Reference Count)和自动释放池(AutoReleasePool)
- 初探swift语言的学习笔记六(ARC-自动引用计数,内存管理)
- iOS内存管理之:引用计数、ARC、自动释放池autoreleasepool和便捷方法之间的关系
- 17-内存管理和自动引用计数
- OC基础15:内存管理和自动引用计数
- cocos2d-x-3.3rc2-004 cocos中的引用计数和自动释放池-ReleasePoolTest
- 黑马程序员——OC基础:内存管理和自动引用计数(ARC)
- 移动开发:iOS内存管理之:引用计数、ARC、自动释放池autoreleasepool和便捷方法之间的关系
- swift语言的学习笔记六(ARC-自动引用计数,内存管理)
- 【Objective-C学习笔记】内存管理——ARC自动引用计数
- iOS内存管理之:引用计数、ARC、自动释放池autoreleasepool和便捷方法之间的关系
- obj-c编程11:内存管理和ARC(自动引用计数)
- 黑马程序员——OC基础:内存管理和自动引用计数(ARC)
- obj-c编程11:内存管理和ARC(自动引用计数)
- iOS内存管理之:引用计数、ARC、自动释放池autoreleasepool和便捷方法之间的关系
- 黑马程序员——Objective-C程序设计(第4版)学习笔记之17-内存管理和自动引用计数——黑马 IOS 技术博客