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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:22:39+00:00 2026-06-01T14:22:39+00:00

when i am analyze my project following code gives me leakage warning. is there

  • 0

when i am analyze my project following code gives me leakage warning. is there any way to solve my memory leakage problem ?

warning :

Potential leak of an object allocated on line 38 and stored into 'addressBook'

Bellow is my code.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    m_tableDataArray = [[[NSMutableArray alloc] init]autorelease];
    NSMutableArray *listDate = [[[NSMutableArray alloc] init]autorelease];
    ABAddressBookRef addressBook = ABAddressBookCreate();
    NSArray *addresses = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);
    NSInteger addressesCount = [addresses count];
    for (int i = 0; i < addressesCount; i++) {
        ABRecordRef record = [addresses objectAtIndex:i];
        NSString *firstName = (NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty);
        NSString *lastName = (NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty);
        if(firstName != nil && lastName != nil){
            NSString *contactFirstLast = [NSString stringWithFormat: @"%@ %@", firstName, lastName];
            [listDate addObject:contactFirstLast];
        }
        [firstName release];
        [lastName release];
    }
    m_tableDataArray = [[NSArray arrayWithArray:listDate] retain];
    [addresses release];
    addresses = nil;
    [m_mainTable reloadData];
}

Thanks in adv…

  • 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-01T14:22:41+00:00Added an answer on June 1, 2026 at 2:22 pm

    Once you have finished using addressBook you need to release it using:

    CFRelease(addressBook);
    

    This should probably be placed at the end of your viewWillAppear: method.

    Updated: There are a few unnecessary arrays and steps in your version of viewWillAppear:. I have cleaned it up a bit and fixed a potential memory leak.

    Note: I haven’t actually run this so double-check that it works correctly.

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        // I assume m_tableDataArray is an instance variable.  If so, if the 
        // view appears multiple times it will result in a leak unless we 
        // release pre-existing instances first.
    
        [m_tableDataArray release], m_tableDataArray = nil;
        m_tableDataArray = [[NSMutableArray alloc] init];
    
        ABAddressBookRef addressBook = ABAddressBookCreate();
    
        NSArray *addresses = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
    
        for (ABRecordRef record in addresses) {
            NSString *firstName = (NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty);
            NSString *lastName = (NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty);
    
            if(firstName != nil && lastName != nil){
                NSString *contactFirstLast = [NSString stringWithFormat: @"%@ %@", firstName, lastName];
                [m_tableDataArray addObject:contactFirstLast];
            }
    
            [firstName release];
            [lastName release];
        }
    
        [addresses release], addresses = nil;
        CFRelease(addressBook);
    
        [m_mainTable reloadData];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a tool to analyze my code project in PyQt4 and draw it
When I build and analyze my project on XCode, I obtain a 'warning' on
I have some memory problems, from another post I tried to analyze my project
Suppose you have the following code: (ns foo) (defmacro defproject [project-name version & args]
I analyze a VB.NET project and there are some objects (child MDI form) that
I use checkstyle to analyze my code. A useful rule is PackageHtml, that checks,
I have to analyze the memory accesses of several programs. What I am looking
I want to analyze an SQL Server stored procedure from .NET code to retrieve
Does anyone know of a way I can code-profile my Windows Sidebar Gadget? I've
I've just mad Build and Analyze with my project on iphone, and i got

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.