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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:28:23+00:00 2026-05-13T08:28:23+00:00

I’m having an issue understanding why releasing an object that I just created is

  • 0

I’m having an issue understanding why releasing an object that I just created is causing a memory access error in my application.

I’m creating a bunch of objects and adding them to an NSMutableArray. After I add them to the array, I release them. The first time the function runs, things go smoothly. The second time the function runs, releasing the object crashes the application and I’m not sure why.

Here is the part of the function in question (full project source is available here: http://github.com/cpjolicoeur/echowaves-notifier-osx)

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];
    NSString *responseString = [[NSString alloc] initWithData:echowaves.responseData encoding:NSUTF8StringEncoding];
    [echowaves.responseData release];

    ...more code...

    [[echowaves updatedConvos] removeAllObjects];
    NSDictionary *dictionary = [responseString JSONValue];
    if ( [dictionary count] ) {
        for (NSDictionary *subscription in dictionary ) {
            UpdatedConvo *convo = [[UpdatedConvo alloc] initWithConvoName:[[subscription objectForKey:@"subscription"] objectForKey:@"convo_name"]
                                                                 convoURI:[[subscription objectForKey:@"subscription"] objectForKey:@"conversation_id"]
                                                              unreadCount:[[[subscription objectForKey:@"subscription"] objectForKey:@"new_messages_count"] integerValue]];


            [[echowaves updatedConvos] addObject:convo];
            [convo release];  // THIS LINE CAUSES CRASH 2ND TIME THROUGH
        }
    } else {

        ...more code....

    }
}            

The app crashes on the [convo release] line the 2nd time through the function. Since the convo object is created two lines before it I’m not sure why.

I’m under the impression that the UpdatedConvo *convo = [[UpdatedConvo alloc] initWithConvoName...] call will create the object and give it a retain count of 1. Then when I add the object to the [echowaves updatedConvos] NSMutableArray object, it should bump the retain count by 1 (now count is 2). I’m done with that “temporary” convo object so I then release it, which should move its retain count back down to 1, correct??

What am I missing here?

To get the app to run successfully, I have to comment out the [convo release] line. I don’t know why though, and I feel that this is probably giving me a slow memory leak since that newly created UpdatedConvo object isn’t being freed from memory properly.

  • 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-13T08:28:24+00:00Added an answer on May 13, 2026 at 8:28 am

    Your method should work. It is a common pattern to create an object, add it to a dictionary, and then release it.

    The fact that it doesn’t work suggests that the problem is elsewhere. The first place to check is in the UpdatedConvo class itself. Does it do anything fancy in its dealloc method?

    edit: The problem is definitely in UpdatedConvo. You assign your instance variables (with =) in your init method:

    - (id)initWithConvoName:(NSString *)convoName
                   convoURI:(NSString *)convoURI
                unreadCount:(int)updatesCount 
    {
        if ( self = [super init] ) {
            ewURI = convoURI;
            ewName = convoName;
            newMessagesCount = updatesCount;
        }
        return self;
    }
    

    But then you call release on them in dealloc:

    - (void)dealloc {
        [ewURI release];
        [ewName release];
        [super dealloc];
    }
    

    Using = in the init method does not increase the retain count, so when you release them, you are actually reducing the retain count too far.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
i got an object with contents of html markup in it, for example: string

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.