• 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
Stumped on memory problem :(
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Stumped on memory problem :(


  • Subject: Stumped on memory problem :(
  • From: Jacob Rhoden <email@hidden>
  • Date: Fri, 02 Jan 2009 12:14:05 +1100

I have read the memory management documentation over and over but still cannot work out the problem with this code, can anyone see it? I have spent hours on this!

+(NSMutableArray*)getStrings {
    NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
    [dict setValue: @"" forKey: [NSString stringWithString:@"one"]];
    [dict setValue: @"" forKey: [NSString stringWithString:@"two"]];

    NSMutableArray *array = [[NSMutableArray array] init];
    NSEnumerator* keyEnum = [dict keyEnumerator];
    NSString* key;
    while ((key = [keyEnum nextObject])) {
        [array addObject: key];
    }
    [dict release];

    return [array autorelease];
}

// Here is where I call the above function
NSMutableArray* a =[StringHelper getStrings];
[a retain];
for(int i=0;i<a.count;i++) {
    NSLog(@"> %@",(NSString*)[a objectAtIndex: i]);
}
[a release];

AFTER the code is complete I see the following message, the address location is always the pointer to the array created in the getStrings method.

2009-01-02 12:07:29.277 Test[5184:813] *** -[CFArray release]: message sent to deallocated instance 0x132950

Any help muchly appreciated. I have tried with and without the [a retain] and [a release].
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Please 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: Stumped on memory problem :(
      • From: Sandy McGuffog <email@hidden>
    • Re: Stumped on memory problem :(
      • From: Graham Cox <email@hidden>
    • Re: Stumped on memory problem :(
      • From: Jeremy Pereira <email@hidden>
    • Re: Stumped on memory problem :(
      • From: Sherm Pendley <email@hidden>
    • Re: Stumped on memory problem :(
      • From: Andy Lee <email@hidden>
    • Re: Stumped on memory problem :(
      • From: "Kyle Sluder" <email@hidden>
    • Re: Stumped on memory problem :(
      • From: Quincey Morris <email@hidden>
    • Re: Stumped on memory problem :(
      • From: Rob Keniger <email@hidden>
    • Re: Stumped on memory problem :(
      • From: Andrew Farmer <email@hidden>
    • Re: Stumped on memory problem :(
      • From: Hsu <email@hidden>
    • Re: Stumped on memory problem :(
      • From: "Stephen J. Butler" <email@hidden>
  • Prev by Date: Re: Visualization strategy/choosing a framework
  • Next by Date: Re: NSOutlineView
  • Previous by thread: Practical error handling question
  • Next by thread: Re: Stumped on memory problem :(
  • Index(es):
    • Date
    • Thread