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 3233318
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:15:47+00:00 2026-05-17T17:15:47+00:00

I have a class like this: @interface MyCollection : NSObject { NSMutableDictionary *data; }

  • 0

I have a class like this:

@interface MyCollection : NSObject {
    NSMutableDictionary *data;
}

and in the implementation of it, I have a method to init it like this:

- (id) init {
    if(self = [super init])
    {
        self.data = [[NSMutableDictionary alloc] init];
    }
    return self;
}

Now when I create a object of this class in my code like this:

MyCollection *c = [[MyCollection alloc] init];

… at which point the Leaks utility shows that I have a memory leak in the init function on the very line where I try to set up the instance variable. I am totally new to Objective C & Iphone and I can’t just get what is going wrong here. I have read through the Memory Management Guide and all, but I think I’m missing something pretty serious here.

Any help would be greatly appreciated. Thanks for your time already.

  • 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-17T17:15:48+00:00Added an answer on May 17, 2026 at 5:15 pm

    you are using self.data =. So there is most likely a property. And it most likely is a property which either copies or retains your object if you use it.
    By calling

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

    The retain count of the NSMutableDictionary increases because of the alloc, and if the property of data has a retain or copy statement you get another increase in retain count.

    you could write data = [[NSMutableDictionary alloc] init]; or self.data = [NSMutableDictionary dictionary]. This would increase the retain count only one time.

    And don’t forget to release the object in dealloc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a class like this: @interface MyAwesomeClass : NSObject { @private NSString
Let's say I have a class that implements the IDisposable interface. Something like this:
If i create a simple class like this @interface table : NSObject { NSMutableArray
This is a little contrived, but say I have a class interface like this:
I have a method like this: void m1(string str) and have a class like
I have a class like this: public class Stretcher : Panel { public static
I have a class like this: public class myClass { public List<myOtherClass> anewlist =
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have a class that looks like this: public class TextField : TextBox {
I have a class which looks something like this: public class Test { private

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.