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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:53:48+00:00 2026-05-16T11:53:48+00:00

I have problem with the way I treat the memory management in iphone..please please

  • 0

I have problem with the way I treat the memory management in iphone..please please help me..I am running out of ideas..I tried to play with the below method but it started leaks when I am trying to allocate the strings for the objects (for example allocation for sid,first_name etc)..I can’t figure out how to do..and this is the method where I will get all the contacts from the service and insert it into the database..It consumes more memory which I figured out by running allocations instrument on iphone and my app on iphone crashes..please please help me guys..What is the better solution for it..I think my app consumes more memory but not sure where to look into it..I can post any code if this is not clear..thanks a lot!!!

- (void) get_entry_listHandler: (id) value{

    NSString *salutation,*sugar_id,*first_name,*last_name,*title1,*department,*phone_home,*phone_mobile,*phone_work,*phone_other,*phone_fax,*assistant,*assistant_phone,*primary_address_street,*primary_address_city,*primary_address_state,*primary_address_postalcode,*custom;
    NSString *primary_address_country,*alt_address_street,*alt_address_city,*alt_address_state,*alt_address_postalcode,*alt_address_country,*date_entered,*date_modified,*deleted,*do_not_call,*birthdate,*lead_source,*description,*email1,*email2,*account_name,*account_id,*id1;

    // Handle errors
    if([value isKindOfClass:[NSError class]]) {
        NSLog(@"%@", value);
        return;
    }

    // Handle faults
    if([value isKindOfClass:[SoapFault class]]) {
        NSLog(@"%@", value);
        return;
    }               

    // Do something with the SCRMget_entry_list_result* result
    SCRMget_entry_list_result* result = (SCRMget_entry_list_result*)value;
    //NSLog(@"get_entry_list returned the value: %@", result);
    //NSLog(@"%@", result.entry_list);
    NSLog(@"%@", result.error);

    SCRMsugarsoap* service = [[SCRMsugarsoap alloc] initWithUrl:serverURL];
    SCRMentry_value* entry;
    for(NSString * myStr in result.entry_list) {
        entry = (SCRMentry_value*)myStr;
        //NSLog(@"1st %@",entry.name_value_list);
        //NSLog(@"1st %@",entry.id);
        //NSLog(@"1st %@",entry.module_name);

        for(NSString * myStr1 in entry.name_value_list) {

            SCRMname_value* value1 = (SCRMname_value*)myStr1;
            if ([value1.name isEqualToString:@"id"])
                sugar_id = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"salutation"])
                salutation = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"first_name"])
                first_name = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"last_name"])
                last_name = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"title"])
                title1 = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"department"])
                department = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"phone_home"])
                phone_home = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"phone_mobile"])
                phone_mobile = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"phone_work"])
                phone_work = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"phone_other"])
                phone_other = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"phone_fax"])
                phone_fax = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"assistant"])
                assistant = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"assistant_phone"])
                assistant_phone = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"primary_address_street"])
                primary_address_street = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"primary_address_city"])
                primary_address_city = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"primary_address_state"])
                primary_address_state = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"primary_address_postalcode"])
                primary_address_postalcode = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"primary_address_country"])
                primary_address_country = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"alt_address_street"])
                alt_address_street = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"alt_address_city"])
                alt_address_city = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"alt_address_state"])
                alt_address_state = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"alt_address_postalcode"])
                alt_address_postalcode = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"alt_address_country"])
                alt_address_country = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"date_entered"])
                date_entered = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"date_modified"])
                date_modified = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"deleted"])
                deleted = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"do_not_call"])
                do_not_call = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"birthdate"])
                birthdate = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"lead_source"])
                lead_source = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"description"])
                description = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"email1"])
                email1 = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"email2"])
                email2 = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else if ([value1.name isEqualToString:@"account_name"])
                account_name = [[NSString alloc] initWithFormat: @"%@",value1.value];


            else if ([value1.name isEqualToString:@"account_id"])
                account_id = [[NSString alloc] initWithFormat: @"%@",value1.value];
            else
                custom = [[NSString alloc] initWithFormat: @"%@",value1.value];
            }

        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setFormatterBehavior:NSDateFormatterBehavior10_4];
        [df setDateFormat:@"yyy-MM-dd HH:mm:ss"];
        NSDate *date_moded = [df dateFromString:date_modified];
        NSDate *lastSync = [df dateFromString:lastSyncTime];
        NSDate *date_enter = [df dateFromString:date_entered];
        [df release];

        if ([[date_moded laterDate:lastSync]isEqualToDate:date_moded] && lastSyncTime != nil && [date_enter isEqualToDate:date_moded])
            id1 = [[NSString alloc]initWithFormat:@"%d",primaryKeyCount];
        else if ([[date_moded laterDate:lastSync]isEqualToDate:date_moded] && lastSyncTime != nil )
            id1 = [db getPrimaryKey:sugar_id];
        else
            id1 = [[NSString alloc]initWithFormat:@"%d",primaryKeyCount];

        [db insertRecordIntoTableNamed: @"Contacts" withField1: @"id" field1Value: id1 andField2: @"sugar_id" field2Value: sugar_id 
                         andField3: @"salutation" field3Value: salutation andField4: @"first_name" field4Value: first_name 
                         andField5: @"last_name" field5Value: last_name andField6: @"title" field6Value: title1 
                         andField7: @"department" field7Value: department andField8: @"phone_home" field8Value: phone_home
                         andField9: @"phone_mobile" field9Value: phone_mobile andField10: @"phone_work" field10Value: phone_work 
                        andField11: @"phone_other" field11Value: phone_other andField12: @"phone_fax" field12Value: phone_fax
                        andField13: @"assistant" field13Value: assistant andField14: @"assistant_phone" field14Value: assistant_phone 
                        andField15: @"primary_address_street" field15Value: primary_address_street andField16: @"primary_address_city" field16Value: primary_address_city 
                        andField17: @"primary_address_state" field17Value: primary_address_state andField18: @"primary_address_postalcode" field18Value: primary_address_postalcode 
                        andField19: @"primary_address_country" field19Value: primary_address_country andField20: @"alt_address_street" field20Value: alt_address_street
                        andField21: @"alt_address_city" field21Value: alt_address_city andField22: @"alt_address_state" field22Value: alt_address_state
                        andField23: @"alt_address_postalcode" field23Value: alt_address_postalcode andField24: @"alt_address_country" field24Value: alt_address_country
                        andField25: @"date_entered" field25Value: date_entered andField26: @"date_modified" field26Value: date_modified 
                        andField27: @"deleted" field27Value: deleted andField28: @"do_not_call" field28Value: do_not_call 
                        andField29: @"birthdate" field29Value: birthdate andField30: @"lead_source" field30Value: lead_source 
                        andField31: @"description" field31Value: description andField32: @"email1" field32Value: email1
                        andField33: @"email2" field33Value: email2 andField34: @"account_name" field34Value: account_name 
                        andField35: @"account_id" field35Value: account_id andField36: @"custom" field36Value: custom];
        primaryKeyCount++;
        currentCount++;
        //NSLog(@"%D",i);
    }
    [salutation release];
    [sugar_id release];
    [first_name release];
    [last_name release];
    [title1 release];
    [department release];
    [phone_home release];
    [phone_mobile release];
    [phone_work release];
    [phone_fax release];
    [phone_other release];
    [assistant release];
    [assistant_phone release];
    [primary_address_street release];
    [primary_address_city release];
    [primary_address_state release];
    [primary_address_postalcode release];
    [primary_address_country release];
    [alt_address_street release];
    [alt_address_city release];
    [alt_address_state release];
    [alt_address_postalcode release];
    [alt_address_country release];
    [custom release];
    [date_entered release];
    [deleted release];
    [do_not_call release];
    [birthdate release];
    [lead_source release];
    [description release];
    [email1 release];
    [email2 release];
    [account_name release];
    [account_id release];

    float expected = (float) contactEntries;
    float gotSoFar = (float) currentCount;


    syncViewController.progressView.progress = ((float)((gotSoFar - 1) / (expected + 1)));
    syncViewController.progressLabel.text=[NSString stringWithFormat:@"Syncing %d Contacts",contactEntries]; 

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    integer = [NSNumber numberWithInt:primaryKeyCount];
    [defaults setObject:integer forKey:@"primaryKeyCount"];
    [defaults synchronize];

    moduleViewController.db = db;
    int a = result.next_offset;
    int b = contactEntries;
    while (result.result_count == 20 /*&& result.next_offset < contactEntries*/) {
        if ( lastSyncTime == nil) {
            [service get_entry_list:self action:@selector(get_entry_listHandler:) session:sessionId module_name: @"Contacts" query: @"" order_by: @"" offset: result.next_offset select_fields: [[[SCRMselect_fields alloc] init]autorelease] max_results: contactEntries deleted: 0];
            [service release];
            return;
            //break;
        }
        else {
            [service get_entry_list:self action:@selector(get_entry_listHandler:) session:sessionId module_name: @"Contacts" query: finalQuery order_by: @"" offset: result.next_offset select_fields: [[[SCRMselect_fields alloc] init]autorelease] max_results: contactEntries deleted: 0];
            [service release];
            return;
            //break;
        }
    }

    if (a >= b ) {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        [settingsViewController.navigationController pushViewController:moduleViewController animated:YES];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setBool:NO forKey:@"reset"];
        [defaults synchronize];
        [finalQuery release];
    }
    /*else if (a >= b && syncing == YES) {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        [moduleViewController reload];
    }*/

    [service release];
    [id1 release];

}

EDIT:

I got rid of all the leaks but can any one please tell me how to check the object allocations instrument in iphone..Please see the below screenshot..My app gets crashed once it loads all the 4200 contacts and the contacts are never displayed on the table view..What might be the problem..I make sure that the place from which my contacts is saved to the database is leak free..In the below screenshot what exactly should I look for..is it the total allocation or living..please let me know guys..I am totally exhausted..thanks a lot for your time..
alt text

  • 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-16T11:53:49+00:00Added an answer on May 16, 2026 at 11:53 am

    You should put the [string release]; lines inside the for(NSString * myStr in result.entry_list) loop. Each time you call alloc, there must be a corresponding release call.

    A better way to do it is to use [NSString stringWithFormat:] instead of [[NSString alloc] initWithFormat:] so that you don’t need to release them manually.

    My app gets crashed once it loads all
    the 4200 contacts and the contacts are
    never displayed on the table viewnever displayed on the table view

    4200 contacts make your loop “large and tight”. As suggested by taskinoor, you can create and drain an NSAutoreleasePool for every a few loops to reduce memory foot print. For example:

    int counter = 0;
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    for (...) {
        if (++counter == 100) {
            counter = 0;
            [pool release];
            pool = [[NSAutoreleasePool alloc] init];
        }
      //busy working...
    }
    [pool release];
    

    Your app may also be terminated by iOS if it takes too long to respond to system events. This mechanism is know as watchdog timeout. In this case, you’ll find the exception code 0x8badf00d in the crash report. You may want to break the work into smaller batches or use a secondary thread so that the main thread won’t be busy for too long.

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

Sidebar

Related Questions

I have a problem and i would like to learn the correct way to
I have a problem as described below Users fill in information in a html
I have a problem where two similar processes are running in parallel within separate
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via
I do not have problem as such but I am quite new to Ruby.

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.