NSDictionary allocation
NSDictionary allocation
- Subject: NSDictionary allocation
- From: Boyd Collier <email@hidden>
- Date: Mon, 14 May 2007 16:44:11 -0700
I want to allocate an NSDictionary and initialize its contents with
arguments passed to it, and to do this within the initialization I
make use of an NSMutableDictionary. But I want the dictionary that's
returned from my initialization to be an NSDictionary rather than the
NSMutableDictionary.
@interface AlleleDictionary : NSDictionary {
}
- (id)initWithSpagediData:(SpagediData*)spagediDataObj locus:(int)locus;
@end
@implementation AlleleDictionary
- (id)initWithSpagediData:(SpagediData*)spagediDataObj locus:(int)
locus {
if ((self = [super init])) {
NSMutableDictionary *theAlleleDict = [[NSMutableDictionary alloc]
initWithCapacity:[spagediDataObj numberOfIndividuals] ];
// code that puts stuff into theAlleleDict (not shown)
self = [[NSDictionary alloc] initWithDictionary:
(NSMutableDictionary*)theAlleleDict copyItems:YES];
[theAlleleDict release];
}
return self;
}
@end
Then the code that calls the above looks like this:
AlleleDictionary *myDict = [[AlleleDictionary alloc]
initWithSpagediData:sharedData locus:0];
Although this seems to work, my gut feeling is that I'm possibly
creating a memory leak. Any comments/suggestions would be much
appreciated.
Boyd
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden