Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6124277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:06:52+00:00 2026-05-23T16:06:52+00:00

Memory management has me confused again — In my .h file, I have: @property

  • 0

Memory management has me confused again —

In my .h file, I have:

@property (nonatomic,retain) NSMutableDictionary *properties;

In my .m, I have the following init method, which complains of a leak in Instruments on the self.properties line:

- (id) init {
  self = [super init];

  self.properties = [[NSMutableDictionary alloc] init];

  return self;
}

It also complains of a leak if I don’t use the accessor.

Likewise, it leaks if I use this strategy:

NSMutableDictionary *temp = [[NSMutableDictionary alloc] init];

self.properties = temp;

[temp release];

And in dealloc I have:

self.properties = nil;
[properties release];

I thought I was following the rules, but this one is alluding me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:06:52+00:00Added an answer on May 23, 2026 at 4:06 pm

    If your .h is defined like this:

    @interface MDObject : NSObject {
        NSMutableDictionary *properties;
    }
    
    @property (nonatomic, retain) NSMutableDictionary *properties;
    
    @end
    

    The following are possible correct implementations of your .m:

    @implementation MDObject
    
    - (id)init {
        if ((self = [super init])) {
             properties = [[NSMutableDictionary alloc] init];
        }
        return self;
    }
    
    - (void)dealloc {
        [properties release];
        [super dealloc];
    }
    
    @end
    

    or

    @implementation MDObject
    
    - (id)init {
        if ((self = [super init])) {
             self.properties = [NSMutableDictionary dictionary];
        }
        return self;
    }
    
    - (void)dealloc {
        self.properties = nil; // while this works,
                               // [properties release] is usually preferred
        [super dealloc];
    }
    
    @end
    

    It might be helpful to remember that

    self.properties = [NSMutableDictionary dictionary];
    

    is the same as

    [self setProperties:[NSMutableDictionary dictionary]];
    

    Those 2 methods that are synthesized for you would look similar to the following:

    - (NSMutableDictionary *)properties {
        return properties;
    }
    
    - (void)setProperties:(NSMutableDictionary *)aProperties {
        [aProperties retain];
        [properties release];
        properties = aProperties;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i m little confused on memory management in following scenario -(NSData *)getData{ NSData *TempData
I have been following this thread: Memory management in Qt? QPushButton::QPushButton ( const QString
This has been killing me.. Because its a memory management issue... I have a
I'm puzzled about iOS memory management. I have a class that has a member
This page has been quite confusing for me. It says: Memory management in newLISP
Quick question regarding memory management in C++ If I do the following operation: pointer
I am trying to understand how memory management goes on low level and have
I know the basic principles about memory management (retain count, autorelease pools etc) in
I'm still shaky on the subtler aspects of memory management, and I have a
I have a question about variable scope and memory management in C. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.