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

  • SEARCH
  • Home
  • 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 980357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:22:07+00:00 2026-05-16T04:22:07+00:00

I am using a singleton class to share data between views in my iphone

  • 0

I am using a singleton class to share data between views in my iphone app. My singleton class contains a dictionary which I allocate in my -init method:

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

    }

    return self;
}

I release it in my dealloc method:

- (void)dealloc
{   
    [dataList release];

    [super dealloc];
}

This dataList is downloaded from a server, and I do this multiple times in my app,so I have a custom setter method to release the old one, and retain the new one:

-(void) setDataList:(NSMutableDictionary*)d    
{
    if( dataList !=nil){

    [dataList release];
    dataList = [d retain];

else 
   dataList = [d retain];
}

ON using the leaks tool, I am getting a memory leak of the dictionary. I think I am doing the alloc and release of the dictionary properly..does the leak occur because the dealloc method of the singleton is not getting called?

Thanks for your help,

Srikanth

  • 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-16T04:22:08+00:00Added an answer on May 16, 2026 at 4:22 am

    Add an autorelease:

    self.dataList = [[[NSMutableDictionary alloc] init] autorelease];
    

    When you assign a an object to a property it retains it and whenever you call and init method it retains, bringing the retain count to 2.

    It also releases when you reassign it so you can just

    self.dataList = newValue;
    

    @syntehsize’d properties take care of all the retain release stuff for you.

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

Sidebar

Related Questions

I'm currently using a singleton as a data store for my app. I essentially
I have tried using a singleton class in my app delegate but I haven't
I'm using a singleton class to save all my settings info. It's first utilized
If I have to write a singleton class in C++ I will be using
I have a class that is a singleton. This singleton is instantiated using GCD
So I'm trying to make an application using the Singleton Method. I want to
I'm working on an iPhone app and facing some troubles with my shared singleton
The goal is to have a singleton data controller class called FetchData.h/.m that pulls
I have an array myArr which contains objects of custom class..e.g. objs of type
I am using a shared instance of a singleton class in a function, do

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.