我有一系列的11嵌入彼此循環,個個0-5:的NSString吃內存
NSPredicate *p
NSString *stringEquation;
for (i=0; i<6; i++) {
for (j=0; j<6; j++) {
etc. . . . .
}
}
最後的循環中,我有評估基於這些迴路數量的表達式迭代:
stringEquation = [NSString stringWithFormat:@"%d.0%@%d.0%@%d.0%@%d.0==24.0",[[theNumbers objectAtIndex:a] intValue],[someOperators objectAtIndex:v],[[theNumbers objectAtIndex:b] intValue],[someOperators objectAtIndex:w],[[theNumbers objectAtIndex:c] intValue],[someOperators objectAtIndex:x],[[theNumbers objectAtIndex:d] intValue]];
p = [NSPredicate predicateWithFormat:stringEquation];
if ([p evaluateWithObject:nil]) {
[theMatches addObject:[NSString stringWithFormat:@"%ld,%ld,%ld,%ld,%ld,%ld,%ld",(long)a,(long)b,(long)c,(long)d,(long)v,(long)w,(long)x]];
fourMatches = fourMatches + 1;
}
NSPredicate和NSString都設置在第一個For循環之前。一切工作正常,它的所有評估正確;但是,每次迭代都會使用內存。我在這裏做錯了什麼?我雖然通過重用相同的NSPredicate和NSString變量,我會節省內存,而不是增加它的使用。
謝謝。