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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:40:12+00:00 2026-05-20T08:40:12+00:00

hope you can help me with this one… I saw some crazy behavior so

  • 0

hope you can help me with this one…
I saw some crazy behavior so far in Objective C but this one makes me suicidal. well, NOT really…

It’s a addressing deallocated object problem.

SCENARIO:
I have tableView with RSS feeds loaded which upon selecting the row opens a DetailView and presents feed in a UIWebView. Since I need function of sliding to previous and next feed from within DetailView, I’m initializing DetailView with NSMutableDictionary that holds
1.) NSMutableArray of all (15) feeds at key:@”items” and
2.) NSNumber positionInArray that has the index of a row selected in the TableView.

The latter I need so I can achieve swipe to previous and next feed by keeping the value of array index at which current feed can be found. With this value I can load positionInArray-1 or positionInArray+1…

In my TableView I have:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 //Call an action only if the pressed cells are not the adMob ones
 if (indexPath.row != 0) {
     NSMutableDictionary *theItem = [[NSMutableDictionary alloc] init]; 
     [theItem setValue:items forKey:@"items"];

     //Add the position of item in the items array to the NSDictionary for current item so it can be
     //used in nextController to scroll to prev and next

     NSNumber *positionInArray = [NSNumber numberWithInt:indexPath.row-1]; 
     [theItem setValue:positionInArray forKey:@"positionInArray"];

     DetailController *nextController = [[DetailController alloc] initWithItem:theItem];
     [self.navigationController pushViewController:nextController animated:YES];

     [nextController release];
    [positionInArray release];
     [theItem release];

 }    

Now, everything works as expected. I select a row in the TableView which opens a DetailView with feed presented. Swiping left and right shows all feeds without problems. BUT! If I select the last feed or the one before last in the TableView, feed is presented as usual but then if I try to swipe left or right I get the following error:

2011-03-03 10:50:15.039 RssReader[72137:207] Swipe Right Movement done!
2011-03-03 10:50:15.041 RssReader[72137:207] *** -[CFNumber intValue]: message sent to deallocated instance 0x6240460

I tried enabling zombies and Guard Malloc but this is the only thing that I got…

The solution of the problem is what really makes me think do I even understand what memory allocation/deallocation means :p
If I remove the line [positionInArray release] OR [theItem release] app will work without any problems??? HOW? WHY? Oh, WHY?

I can pretend that I understand that if I release the positionInArray object it cannot be passed around inside the other object NSMutableDictionarytheItem. I say pretend because I thought it’s using a copy of it (by assigning).

Also, what I can’t understand is:

  1. why does it work for 13 feeds that I load and for the last two it doesn’t?

  2. why does it work if I don`t release theItem object? I mean just few lines above that object was used to initialize the *nextController and there I made a local copy of it to work with it?

If you need more information, please ask what could help you and I’ll definitely provide it…
Thanks in advance,
L

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

    These lines are your problem:

    NSNumber *positionInArray = [NSNumber numberWithInt:indexPath.row-1]; 
    
    [positionInArray release];
    

    You are alloc/initing all your other variables. That means you are responsible for releasing them. With the NSNumber instance, you aren’t calling alloc, so you aren’t responsible for releasing it, it’s autoreleased. By releasing it yourself, it means that somewhere at a later stage in your app, when the autorelease pool is being drained, it’s being deallocated for a second time, hence the hard-to-debug error.

    For more details, read the Memory Management Programming Guide

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

Sidebar

Related Questions

hope you can help with this one (or even improve it - which won't
hope you can help me on this one, I'm currently using this: jQuery plugin:validation
I hope someone can help me with this one, I suspect I am doing
I hope you guys can help me with this one. So, I have a
i hope you can help me with this one. The code is supposed to
I hope some one can help me with that. I have a TabBar with
I hope there's a SharePoint expert here on SO who can help with this.
this is my first question here so I hope I can articulate it well
I hope someone can help... This issue has been discussed here and I have
I have a problem that I hope you can help/guide me. I saw a

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.