Index: utils/objfw-new/NewClass.m ================================================================== --- utils/objfw-new/NewClass.m +++ utils/objfw-new/NewClass.m @@ -31,10 +31,11 @@ newClass(OFString *name, OFString *superclass, OFMutableArray *properties) { OFString *headerPath = [name stringByAppendingPathExtension: @"h"]; OFString *implPath = [name stringByAppendingPathExtension: @"m"]; OFFile *headerFile = nil, *implFile = nil; + bool needsDealloc = false; @try { headerFile = [OFFile fileWithPath: headerPath mode: @"wx"]; implFile = [OFFile fileWithPath: implPath mode: @"wx"]; } @catch (OFOpenItemFailedException *e) { if (e.errNo != EEXIST) @@ -86,10 +87,14 @@ for (OFString *attribute in property.attributes) { if ([attribute isEqual: @"nullable"]) continue; + if ([attribute isEqual: @"retain"] || + [attribute isEqual: @"copy"]) + needsDealloc = true; + if (!first) [headerFile writeString: @", "]; [headerFile writeString: attribute]; first = false; @@ -112,11 +117,27 @@ headerPath, name]; for (Property *property in properties) [implFile writeFormat: @"@synthesize %@ = _%@;\n", property.name, property.name]; + + if (needsDealloc) { + [implFile writeString: @"\n" + @"- (void)dealloc\n" + @"{\n"]; + + for (Property *property in properties) + if ([property.attributes containsObject: @"retain"] || + [property.attributes containsObject: @"copy"]) + [implFile writeFormat: @"\t[_%@ release];\n", + property.name]; + + [implFile writeString: @"\n" + @"\t[super dealloc];\n" + @"}\n"]; + } [implFile writeString: @"@end\n"]; [headerFile close]; [implFile close]; }