I have made a very simple custom object pictureData.
Here is the .h file
#import <Foundation/Foundation.h>
@interface pictureData : NSObject {
NSString *fileName;
NSString *photographer;
NSString *title;
NSString *license;
}
@property (nonatomic, retain) NSString *fileName;
@property (nonatomic, retain) NSString *photographer;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *license;
+(pictureData*)picDataWith:(NSDictionary*)dictionary;
@end
The .m file
#import "pictureData.h"
@implementation pictureData
@synthesize fileName;
@synthesize photographer;
@synthesize title;
@synthesize license;
+ (pictureData*)picDataWith:(NSDictionary *)dictionary {
pictureData *tmp = [[[pictureData alloc] init] autorelease];
tmp.fileName = [dictionary objectForKey:@"fileName"];
tmp.photographer = [dictionary objectForKey:@"photographer"];
tmp.title = [dictionary objectForKey:@"title"];
tmp.license = [dictionary objectForKey:@"license"];
return tmp;
}
-(void)dealloc {
[fileName release];
[photographer release];
[title release];
[license release];
}
@end
I then set up these objects in an array, like so:
NSString *path = [[NSBundle mainBundle] pathForResource:@"pictureLicenses" ofType:@"plist"];
NSArray *tmpDataSource = [NSArray arrayWithContentsOfFile:path];
NSMutableArray *tmp = [[NSMutableArray alloc] init];
self.dataSource = tmp;
[tmp release];
for (NSDictionary *dict in tmpDataSource) {
pictureData *pic = [pictureData picDataWith:dict];
NSLog(@"%@", pic.title);
[self.dataSource addObject:pic];
}
Everything works smashingly. I have a table view which loads the proper picture images, and information, no problem. Upon running Instruments for leaks, I see that my pictureData object is leaks with every allocation.
I would assume that with having my object autoreleased I would not have to worry about manually allocating and deallocating them.
Perhaps is my issue that I use autorelease, which the autoReleasePool keeps a retain count of +1 and then when I add a pictureData object to my array, that also retains it? Thank you all for your time!
edit: Don’t forget to call super! Thank you Sam!
Change dealloc to:
(call
[super dealloc])