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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:28:29+00:00 2026-05-24T11:28:29+00:00

Yesterday I assked a question about memory management and Singletons ( Proper Management Of

  • 0

Yesterday I assked a question about memory management and Singletons ( Proper Management Of A Singleton Data Store In IOS With Web Service ). I have been racking my brain for the past 36 hours trying to track down the issue and after extensive testing with NSLog, etc, I can only conclude that objects allocated within blocks are not being autoreleased. I’ve used blocks as a way to handle the asynchronous webservice responses. I also send a block from the view controller that needs to make the web service request so that it can perform any actions based on the web service’s response. In the hopes that a comprehensive overview of my code will help obtain a solution, I’m putting all the code that is generating the issue here:

The first step is making a request from my root view controller. When it loads, I request all the user’s “Hollers” a term that I’m using internally to essentially mean events. When the root view controller loads, I call a method which contains the following code:

HollerWebService *api = [[HollerWebService alloc]init];
//NSLog(@"About to get the hollers for userId: %@", [[[CurrentSession defaultStore]currentUser]userId]);
[api getLatestHollers:[[[CurrentSession defaultStore]currentUser]userId] completionBlock:^(BOOL succeeded) {
    //If the user has 0 hollers, display one of the illustrations
    [self.tableView reloadData];
    [self stopLoading];
    if( !succeeded ){
        UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not connect to Holler" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [av show];
        [av release];
    }
    else
    {
        for( Holler *hN in [[HollerStore defaultStore] allHollers] )
        {
            //Retain count of all the hollers is 
            NSLog(@"Retain count of the holler is %i", [hN retainCount]);
        }
    }
}];

[api release];

As you can see, I have a commented area which prints out the retain count to NSLog that was part of my debugging process. At this point, it’s telling me the retain count of each object is 2, meaning that the original Holler generated in the next set of code has not yet been autoreleased. The next set of code is within my actual web service. I have included comments around the key part of this method which is resulting in increased retain counts:

- (void)getLatestHollers: (NSString *)userId completionBlock:(void (^)(BOOL succeeded))handler
{
    [self getRequest:[[NSString alloc]initWithFormat:@"hollers/feed?user_id=%@",userId] completionBlock:^(NSData *receivedData, NSURLResponse *receivedResponse, NSError *error) {
    if( error == nil )
    {
        SBJsonParser *json = [SBJsonParser new];
        NSArray *response = [json objectWithData:receivedData];
        [json release];
        //NSLog(@"Got the latest Hollers. %@", response);
        HollerStore *hStore = [HollerStore defaultStore];
        for( NSDictionary *holler in response )
        {
            //At this point Holler *h is being sent an autoreleased holler
            //from the parseHoller: method.  At this point it's retain count is 1
            Holler *h = [self parseHoller:holler];
            [hStore addHoller:h];
            //Now that I've added it to my singleton the retain count is 2, although I'm 
            //assuming the autorelease pool will eventually come through and reduce this 
            //to 1 but it never happens
        }
        handler(YES);
    }
    else
    {
        NSLog(@"The API failed :(, %@", [error localizedDescription]);
        //Let the requestor know that this request failed
        handler(NO);
    }
    }];
}

At this point the retain count remains at 2, not 1, so when I go to remove the object from my singleton, it results in a memory leak. The only thing that I can conclude is that I’m having some sort of block-related memory issues. If anybody could provide some insight it would be much appreciated!!!

  • 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-24T11:28:32+00:00Added an answer on May 24, 2026 at 11:28 am

    You should never be using retainCount at all, ever – really Apple should just remove it from the SDK as it’s not useful at all. Check out this question for the technical reasons as to why you shouldn’t be using it point blank:

    When to use -retainCount?

    I am going to hop over to the original question where somebody posted that you should use it and point this out. You may well have a memory leak, but retain count isn’t the right thing to use to solve it!

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

Sidebar

Related Questions

I asked a question about bigints yesterday which was kindly answered. However, I have
Yesterday , I asked a question about socket post file data to php page.
I already asked a question about this yesterday, but now I have another :)
Yesterday I asked this general question about decimals and their internal precisions. Here is
I asked a question about different testing frameworks yesterday. This question can be found
I asked a question about making a greatest n per group type query yesterday
Yesterday I asked about serving byte ranges from PHP. Today my question is -
I asked a question yesterday about password safety... I am new at security... I
As an answer to a question I asked yesterday ( New Core Data entity
I asked a fairly poor question yesterday, but I still have the same general

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.