首页 > 代码库 > 完美释放实例变量的内存,定义成宏的形式

完美释放实例变量的内存,定义成宏的形式


完美释放内存,麻烦自己方便他人...

定义成宏的形式:

#define RELEASE_SAFE(_Pointer) do{[_Pointer release],_Pointer = nil;}while(0

例:

//姓名

@property (nonatomic,copy)NSString *name;

//性别

@property (nonatomic,copy)NSString *gender;

//年龄

@property (nonatomic,copy)NSString *age;

//联系方式

@property (nonatomic,copy)NSString *phoneNumber;

//图片名

@property (nonatomic,copy)NSString *imageName;

- (void)dealloc

{

   RELEASE_SAFE(_name);

   RELEASE_SAFE(_gender);

   RELEASE_SAFE(_age);

   RELEASE_SAFE(_phoneNumber);

   RELEASE_SAFE(_imageName);

    [super  dealloc];

}


完美释放实例变量的内存,定义成宏的形式