• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSDictionary allocation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSDictionary allocation
      • From: Bill Bumgarner <email@hidden>
    • Re: NSDictionary allocation
      • From: "Adam R. Maxwell" <email@hidden>
    • Re: NSDictionary allocation
      • From: Nick Zitzmann <email@hidden>
    • Re: NSDictionary allocation
      • From: Jean-Olivier Lanctôt <email@hidden>
  • Prev by Date: Re: Progress Indicator Behaviour
  • Next by Date: Re: NSDictionary allocation
  • Previous by thread: export movie to avi using qtkit
  • Next by thread: Re: NSDictionary allocation
  • Index(es):
    • Date
    • Thread