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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:05:55+00:00 2026-06-07T11:05:55+00:00

I have a UITableView and I implemented the delete from table swipe method. For

  • 0

I have a UITableView and I implemented the delete from table swipe method.
For some reason, the assignment of arrays is causing the app to crash.
I would like to know why.

two properties:

@property (nonatomic,retain) NSMutableArray *mruItems;
@property (nonatomic,retain) NSArray *mruSearchItems;
 . 
 .
 .
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle != UITableViewCellEditingStyleDelete)
        return;

    NSString *searchString = [self.mruSearchItems objectAtIndex:indexPath.row];
    [self.mruItems removeObject:searchString];

    [self.mruSearchItems release];

    // This line crashes:
    self.mruSearchItems = [[NSArray alloc] initWithArray:self.mruItems];

    [self.searchTableView reloadData];
   }

It is as if after mruItems’s objects has been removed, it can’t help initialize mruSearchItems…

Thanks!

EDIT:

EXC_BAD_ACCESS

@synthesize mruItems,mruSearchItems; <–Debugger points here

  • 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-06-07T11:05:57+00:00Added an answer on June 7, 2026 at 11:05 am

    It is double releasing causes crash.

    [self.mruSearchItems release];
    

    This makes refcount -1

    self.mruSearchItems = [[NSArray alloc] initWithArray:self.mruItems];
    

    This makes refcount -1

    Since mruSearchItems has “retain” in property attributes, your assign to it will cause another refcount -1.

    So either remove the release line or set it to nil after release it and before assign to it.


    Edit:
    This line

    self.mruSearchItems = [[NSArray alloc] initWithArray:self.mruItems];
    

    causes memory leak, fix it like this:

    self.mruSearchItems = [[[NSArray alloc] initWithArray:self.mruItems] autorelease];
    

    or:

    NSArray *tmpArray = [[NSArray alloc] initWithArray:self.mruItems];
    self.mruSearchItems = tmpArray;
    [tmpArray release];
    

    Edit Again

    What does “retain” in property actually do?

    Take mruSearchItems as example, when you assign it:

    - (void)setMruSearchItems:(NSArray *)newArray
    {
        [newArray retain];
        [mruSearchItems release]; // this lines causes a second release to the old value
        mruSearchItems = newArray;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented the search method for a UITableView populate from a NSArray (mylist):
In cellForRowAtIndexPath: method I have implemented gesture recognizer for long press, -(UITableViewCell *)tableView:(UITableView *)tableView
For my iPhone app, I have an editable (for delete) table view. I'd like
I have UITableView . in tableView:cellForRow:atIndexPath: method (when data populates to cells) I've implemented
I have implemented a UITableView with the NSFetchedResultsController to load data from an sqllite
So I have a UIWebView implemented in one .m file and a UITableView implemented
I have implemented cell.selectionStyle = UITableViewCellSelectionStyleNone; both in: -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
I have a UITableView on a UIViewController. And this table has say 5 visible
I have a UITableView that lists comments from various users. I save all of
I have a UITableView with custom UITableViewCells. The table has two sections, the first

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.