Search code examples
objective-ccore-datamemory-leaksnsarray

NSArray filteredArrayUsingPredicate memory leak


I am get a huge memory leak when trying to use NSPredicate in a for-loop to search for records in a NSArray that has a NSDate field value within a date range - like this:

for(int i=0;i<nLen;i++)
{
  NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date >=  %@ AND date <=  %@", dateStart,dateEnd];
  NSArray *result = [myDataArray filteredArrayUsingPredicate:predicate];
} 

Simple testing suggests that it is the filteredArrayUsingPredicate function that is leaking.

Using XCode Version 9.2 (9C40b) and iOS 11.2.1 on a iPhone 7s.

Has anyone else seen this?


Solution

  • Willeke's response is the answer : Put an @autoreleasepool block inside the loop. Thanks!