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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:20:39+00:00 2026-06-15T18:20:39+00:00

+ (NSArray *) fetchAllContactsInContext:(NSManagedObjectContext *)a_context { NSFetchRequest *_request = [[NSFetchRequest alloc] init]; [_request setEntity:[NSEntityDescription

  • 0
+ (NSArray *) fetchAllContactsInContext:(NSManagedObjectContext *)a_context
{
    NSFetchRequest *_request = [[NSFetchRequest alloc] init];
    [_request setEntity:[NSEntityDescription entityForName:@"Contact" inManagedObjectContext:a_context]];

    NSSortDescriptor *_sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
    NSArray *_sortDescriptors = [[NSArray alloc] initWithObjects:_sortDescriptor, nil];
    [_request setSortDescriptors:_sortDescriptors];

    NSError *_fetchError=nil;
    NSArray *_results = [[NSArray alloc] initWithArray:[a_context executeFetchRequest:_request error:&_fetchError]];
    [_sortDescriptor release];
    [_sortDescriptors release];
    [_request release];

    if (_fetchError){
        NSLog(@"Contact - Error fetching contacts %@", [_fetchError localizedDescription]);
    }
    [_fetchError release];
    return [_results autorelease];
}

I wanna ask, Is this function leaking memory? Actually Instruments is saying that this function is leaking hell lot of memory.

Can you please help me resolving the memory issue?

  • 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-15T18:20:40+00:00Added an answer on June 15, 2026 at 6:20 pm

    If you need to see where retains, releases and autoreleases occur for an object use instruments:

    Run in instruments, in Allocations set “Record reference counts” on on (you have to stop recording to set the option). Cause the problem code to run, stop recording, search for there ivar of interest, drill down and you will be able to see where all retains, releases and autoreleases occurred.

    enter image description here

    Here is a simplifies version using ARC for iOS 4.3 and up:

    + (NSArray *) fetchAllContactsInContext:(NSManagedObjectContext *)aContext {
        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Contact"];
    
        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
        [request setSortDescriptors:@[sortDescriptor]];
    
        NSError *fetchError;
        NSArray *results = [aContext executeFetchRequest:request error:&fetchError];
    
        if (results == nil){
            NSLog(@"Contact - Error fetching contacts %@", [fetchError localizedDescription]);
        }
        return results;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

-(NSArray*)getSomeStuff { NSMutableArray *array = [[NSMutableArray alloc]init]; // Add some objects to array return
- (NSArray *) makeKeyValueArray: (NSArray *) arr { NSMutableArray *result = [[NSMutableArray alloc] init];
NSArray *array = [dictionary objectForKey:@field]; and NSArray *array = [[NSArray alloc] initWithArray:[dictionary objectForKey:@field]]; I
Consider the following NSArray: NSArray *dataSet = [[NSArray alloc] initWithObjects: [NSDictionary dictionaryWithObjectsAndKeys:@abc, @key1, @def,
NSArray chemConstantArray = [[NSArray alloc] initWithObjects:0.0021400, 0.0012840, 0.0010700, nil]; Gives me four errors: Incompatible
I have a method: -(NSArray *)doSomething{ NSArray *array = [[NSArray alloc] initWithObjects:@Huy 1,@Huy 2,@Huy
+ (NSArray*) queryAllByEntityName:(NSString*) name AndSortColumn:(NSString*) ptyName{ //Define our entity to use NSEntityDescription *entity =
NSArray *array = [[NSArray alloc] initWithObjects:@ΕΛΤΑ, @ΕΛΤΑ COURIER, @ACS, @ACS ΕΞΩΤΕΡΙΚΟ, @DHL, @INTERATTICA, @SPEEDEX,
NSArray *subviewsList = [[NSArray alloc] initWithArray:[self.view subviews]]; for (UIView *aView in subviewsList) { NSLog(@%@,subviewsList);
NSArray *itemArray = [NSArray arrayWithObjects:@one, @Two, @Three, nil]; segmentControl = [[UISegmentedControl alloc] initWithItems:itemArray]; segmentControl.frame

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.