Search code examples
ios6uisearchbaruisearchdisplaycontrollerlag

Memory allocation differences in IOS6?


Since i updated my iOS software on my iPhone 4, my app that i'm developing has started to lag. This is only happening when i'm giving inputs to a UISearchField.

The "lag" occurs when i've tapped around 30 letters on the iOS keyboard. After that, every consecutive tap lags behind giving the feel that the phone itself can't handle the inputs anymore.

I have a UISearchDisplayController that does Selects to my database whenever i enter three or more letters in my search field.

Here is some code.

The actual search

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{


    if ([searchText length] >= 3)
    {


        if (searchObject != nil)
        {
            searchObject = nil;
            searchObject = [[FritextSok alloc]init];
            [searchObject setDelegate:self];
        }

        [searchObject setSearchstring:searchText];

        [searchObject search];



    }
    else
    {

        // Displays non filtered results.
    }


}

I'm also experiencing this while running the iOS6 simulator.

Also, aside from the iOS keyboard "lag". Every single UISegmentedControl, in different view controllers seems to take FOREVER to draw. This happens after the keyboard mash.

I'm properly reusing cells ( i think ) and have no actual idea what's causing this, since it seems to run perfectly on all iOS versions from 4.3 up to 5.1.

I've tried different ways of allocating the searchObject. Nothing seems to help.

Edit

This is an error message that shows up sporadicly

purgeIdleCellConnections: found one to purge conn = <Memory address>

Edit 2

After some more trial and error with use of the PROFILER-tool. I discovered that the living memory is constantly increasing due to this block.

UISegmentedControl *segment = [[UISegmentedControl alloc] init];
segment.frame = CGRectMake(0, 0, 70, 32);
segment.selectedSegmentIndex = -1;
segment.segmentedControlStyle = UISegmentedControlStyleBar;
segment.tintColor = [UIColor colorWithRed:0.745 green:0.184 blue:0.216 alpha:1];
segment.momentary = YES;
segment.alpha = 0.9;
[segment insertSegmentWithTitle:@"Ta bort" atIndex:0 animated:NO];
[segment addTarget:self action:@selector(foo:) forControlEvents:UIControlEventValueChanged];

The above block is being run every time i enter a character in the UISearchField. Since the UISearchDisplayDelegate is returning YES for the -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString function. Which results in a re-drawing of the UITableView and it's cells.

The problem has now become somewhat easier to handle. And i'm currently implementing a possible fix.


Solution

  • Solution:

    Move code

    UISegmentedControl *segment = [[UISegmentedControl alloc] init];
    segment.frame = CGRectMake(0, 0, 70, 32);
    segment.selectedSegmentIndex = -1;
    segment.segmentedControlStyle = UISegmentedControlStyleBar;
    segment.tintColor = [UIColor colorWithRed:0.745 green:0.184 blue:0.216 alpha:1];
    segment.momentary = YES;
    segment.alpha = 0.9;
    [segment insertSegmentWithTitle:@"Ta bort" atIndex:0 animated:NO];
    [segment addTarget:self action:@selector(foo:) forControlEvents:UIControlEventValueChanged];
    

    Outside of the actual re-drawing of the tableview.