iPad search bar bad memory access?
So I am trying to implement a search bar in my app and am very close but can't seem to figure out where this memory error is occurring. This is what part of my search method looks like:
filters = [[NSMutableArray alloc] init];
NSString *searchText = detailSearch.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
// Normally holds the object (ex: 70 locations)
searchArray = self.copyOfFilters ;
//This is the line that is breaking after ~2-3 letters are entered in the search
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[filters addObject:sTemp];
}
displayedFilters = filters;
copyOfFilters is a deep copy of the displayed filters that appear when the view first loads via:
self.copyOfFilters = [[NSMutableArray alloc] initWithArray:displayedFilters copyItems:YES];
I have traced through the entry of let开发者_如何转开发ters and it is accurate after 2 letters, but once you try and enter a letter after a space in the search bar, it crashes. The value of copyOfFilters = {(int)[$VAR count]} objects. Does anyone know what may be causing this? Thanks!
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
// Normally holds the object (ex: 70 locations)
searchArray = self.copyOfFilters ;
is a really basic memory leak. You create a NSMuatbleArray and loose any chance to release it with the next statement.
Be sure you don't release or change copyOfFilters or searchArray anywhere in your code.
did you release filters while still calling displayedFilters?
Im wondering if you are having a problem when self.copyOfFilters is modified or so. Try
searchArray = [self.copyOfFilters copy] ;
Dont forget to release searchArray after the loop. This might be a shot in the dark but might be worth a shot?
精彩评论