I'm running the Instruments application with the Leaks template and it's telling me that I have a leak at the line:
我正在使用Leaks模板运行Instruments应用程序,它告诉我在线路上有泄漏:
NSArray *tempFavs = [tempFavString componentsSeparatedByString:@"|"];
I've seen some other people having similar problems but I haven't seen any solutions. It seems that this array should be autoreleased and I shouldn't have to worry about it. All of the arrays that I've alloc'd are released in the dealloc method. Here's all of the relevant code:
我见过其他一些人有类似的问题,但我没有看到任何解决方案。似乎这个数组应该是自动释放的,我不应该担心它。我分配的所有数组都在dealloc方法中释放。这是所有相关代码:
NSArray *tempFavoritesArray = [appPreferences arrayForKey:[NSString stringWithFormat:@"%@ %@ favorites", server, project]];
favoritesArrayDisplay = [[NSMutableArray alloc] initWithObjects:nil];
cenXsArray = [[NSMutableArray alloc] initWithObjects:nil];
cenYsArray = [[NSMutableArray alloc] initWithObjects:nil];
viewScalesArray = [[NSMutableArray alloc] initWithObjects:nil];
currentPresetsArray = [[NSMutableArray alloc] initWithObjects:nil];
rastersArray = [[NSMutableArray alloc] initWithObjects:nil];
empty = NO;
selected = NO;
if ([tempFavoritesArray count] == 0 || tempFavoritesArray == nil)
{
[favoritesArrayDisplay addObject:@"No favorites saved."];
empty = YES;
}
for (int i=0; i<[tempFavoritesArray count]; i++)
{
NSString *tempFavString = [NSString stringWithString:[tempFavoritesArray objectAtIndex:i]];
NSArray *tempFavs = [tempFavString componentsSeparatedByString:@"|"];
if ([tempFavs count] > 2)
{
[favoritesArrayDisplay addObject:[tempFavs objectAtIndex:0]];
[cenXsArray addObject:[tempFavs objectAtIndex:1]];
[cenYsArray addObject:[tempFavs objectAtIndex:2]];
[viewScalesArray addObject:[tempFavs objectAtIndex:3]];
[currentPresetsArray addObject:[tempFavs objectAtIndex:4]];
[rastersArray addObject:[tempFavs objectAtIndex:5]];
}
}
Has anyone seen this before?
有没有人见过这个?
3 个解决方案
#1
5
All leaks is telling you is that an object or objects allocated by that line of code are later leaked. It is not showing you the line of code that caused the actual leak, but the line of code that created the allocation that was later leaked.
所有泄漏都告诉您,该行代码分配的一个或多个对象稍后会泄露。它没有显示导致实际泄漏的代码行,而是显示创建后来泄漏的分配的代码行。
I.e. you may be over-retaining one of the strings in the tempFavs
array and leaks is identifying it as a leaked allocation.
即你可能会过度保留tempFavs数组中的一个字符串,而泄漏则将其识别为泄漏分配。
First, try "build and analyze". If that doesn't fix the problem, use the Allocations instrument to figure out exactly which object was leaked and where it was retained/released.
首先,尝试“构建和分析”。如果这不能解决问题,请使用Allocations工具确切地确定泄漏的对象以及保留/释放的对象。
#2
1
You say that all of the arrays that you've alloc'd are released in the dealloc method, but are you positive that this dealloc is being called? Maybe you're actually leaking the object that contains all those arrays.
你说你分配的所有数组都是在dealloc方法中释放的,但是你是否肯定这个dealloc被调用?也许你实际上泄漏了包含所有这些数组的对象。
#3
0
Haven't seen anything about componentsSeparatedByString increasing the retain count, but you're sure you're not retaining any of the NSArray's somewhere else in the class?
还没有看到有关componentsSeparatedByString增加保留计数的任何内容,但你确定你没有在类中的其他地方保留任何NSArray?
#1
5
All leaks is telling you is that an object or objects allocated by that line of code are later leaked. It is not showing you the line of code that caused the actual leak, but the line of code that created the allocation that was later leaked.
所有泄漏都告诉您,该行代码分配的一个或多个对象稍后会泄露。它没有显示导致实际泄漏的代码行,而是显示创建后来泄漏的分配的代码行。
I.e. you may be over-retaining one of the strings in the tempFavs
array and leaks is identifying it as a leaked allocation.
即你可能会过度保留tempFavs数组中的一个字符串,而泄漏则将其识别为泄漏分配。
First, try "build and analyze". If that doesn't fix the problem, use the Allocations instrument to figure out exactly which object was leaked and where it was retained/released.
首先,尝试“构建和分析”。如果这不能解决问题,请使用Allocations工具确切地确定泄漏的对象以及保留/释放的对象。
#2
1
You say that all of the arrays that you've alloc'd are released in the dealloc method, but are you positive that this dealloc is being called? Maybe you're actually leaking the object that contains all those arrays.
你说你分配的所有数组都是在dealloc方法中释放的,但是你是否肯定这个dealloc被调用?也许你实际上泄漏了包含所有这些数组的对象。
#3
0
Haven't seen anything about componentsSeparatedByString increasing the retain count, but you're sure you're not retaining any of the NSArray's somewhere else in the class?
还没有看到有关componentsSeparatedByString增加保留计数的任何内容,但你确定你没有在类中的其他地方保留任何NSArray?