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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:57:45+00:00 2026-05-24T23:57:45+00:00

I recently started learning objective-C and cocoa. I’m slowly starting to learn about memory

  • 0

I recently started learning objective-C and cocoa. I’m slowly starting to learn about memory management. Usually i kinda grasp the logic of it. But right now i’m kinda confused. Here’s my problem:

I am trying to make a simple ios app with search function. I have a UISearchDisplayController with a UISearchbar inside a UITableViewController that leaks (instruments..) like hell when I type something in it. Compiler and Analyzer both show no warnings or errors. Just instruments.

I get the error from this line inside the handleSearchTerm method:

self.searchResults = [[datenSort filteredArrayUsingPredicate:predicate] mutableCopy];

Here’s my handleSearchTerm method:

- (void)handleSearchForTerm:(NSString *)searchTerm
{   
    self.savedSearchTerm = searchTerm;
    if ([self searchResults] == nil)
    {    

       NSMutableArray *array = [[NSMutableArray alloc] init];       
       self.searchResults = array;
       [array release], array = nil;
    }

    [[self searchResults] removeAllObjects];
    if ([[self savedSearchTerm] length] != 0)
    {

       NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(Name contains[cd] %@)", searchTerm];
       self.searchResults = [[datenSort filteredArrayUsingPredicate:predicate] mutableCopy];

      }


}

the properties are all released in the dealloc method. and they are:

@property (nonatomic, copy) NSString *savedSearchTerm;
@property (nonatomic, retain) NSMutableArray *datenSort;
@property (nonatomic, retain) NSMutableArray *searchResults;

and this is how i put them inside tableview:cellForRowAtIndexPath:

    if(tableView == self.searchDisplayController.searchResultsTableView){

        dataItem = [searchResults objectAtIndex:indexPath.row];

    }else {

        dataItem = [datenSort objectAtIndex:indexPath.row];

    }

your answers are VERY 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-24T23:57:46+00:00Added an answer on May 24, 2026 at 11:57 pm

    This line leaks:

    self.searchResults = [[datenSort filteredArrayUsingPredicate:predicate] mutableCopy];
    

    According to the Memory Management rules, you own any object you create and you create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy”.

    Therefore, mutableCopy returns a retained object and the searchResults property setter also retains the object, resulting in the object being over-retained. The solution is to relinquish ownership of the object by sending it a release…

    NSArray *temp = [[datenSort filteredArrayUsingPredicate:predicate] mutableCopy];
    self.searchResults = temp;
    [temp release];
    

    …or autorelease message.

    self.searchResults = [[[datenSort filteredArrayUsingPredicate:predicate] mutableCopy] autorelease];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I've started learning about Contexts in .NET (context-bound, context-agile, message sinks, etc.). Several
I've recently started learning C#. I just learned about properties and decided to make
I recently started learning about Chrome Extensions and was taking a look at the
I've recently started learning about .net and the Windows API and I'm currently writting
Recently I started learning C++. I'm used to programing in Objective-C so maybe I'm
I recently started learning Objective-C 2.0, with a book, and I want to know
I recently started learning about ASP.Net MVC and its various features MVC_3_MUSIC_STORE + CODE
I recently started learning about HttpModules and made my first one. I was wondering
I recently started learning the CodeIgniter framework and i was wondering about one thing:
I just recently started learning Java. I have a question which is more about

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.