//运用OC的动态属性,释放属性的内存
- (void)dealloc
{
Class clazz = [self class];
u_int count;
objc_property_t *properties = class_copyPropertyList(clazz, &count);
for (int i =0; i<count; i++) {
const char *propertyName = property_getName(properties[i]);
NSString *name = [NSString stringWithCString:propertyName encoding:NSUTF8StringEncoding];
SEL selector = NSSelectorFromString(name);
if (selector) {
id variable = [self performSelector:selector];
if (variable != [NSNull null] && variable) {
[variable release];
variable = nil;
}
}
}
free(properties);
[super dealloc];
}
备注:将上面代码弄成XCODE的代码片段,基本上每个类都可以直接copy进去,省心省力
- (void)dealloc
{
Class clazz = [self class];
u_int count;
objc_property_t *properties = class_copyPropertyList(clazz, &count);
for (int i =0; i<count; i++) {
const char *propertyName = property_getName(properties[i]);
NSString *name = [NSString stringWithCString:propertyName encoding:NSUTF8StringEncoding];
SEL selector = NSSelectorFromString(name);
if (selector) {
id variable = [self performSelector:selector];
if (variable != [NSNull null] && variable) {
[variable release];
variable = nil;
}
}
}
free(properties);
[super dealloc];
}
备注:将上面代码弄成XCODE的代码片段,基本上每个类都可以直接copy进去,省心省力