我在仪器中有内存泄漏......我之前已经对它进行了一些排序,但是这个让我感到难过!如果你可以提供帮助,我将非常感激...这是泄漏的方法......它接收数据字典,基于它创建一个新的并返回它。我已经评论了泄漏的线条,以及它给泄漏的百分比(不确定那是什么),我试图通过选择alloc / init / release而不是autorelease来清理一些东西,但是似乎没有任何区别......
- (PetalLayerView *)makePetalLayerWithData:(NSDictionary *)sectionData isZeroIndexed(BOOL)zeroIndexed
{
NSMutableSet *petalsData = [[NSMutableSet alloc] init]; // 7.2%
NSArray *sections = [sectionData objectForKey:@"sections"];
NSNumber *startIndex, *endIndex;
NSDictionary *petalData;
for(int i=0; i<sections.count; i++)
{
startIndex = [sections objectAtIndex:i];
if(i < sections.count - 1)
endIndex = [sections objectAtIndex:i+1];
else
endIndex = [sections objectAtIndex:0];
if(!zeroIndexed)
{
startIndex = [NSNumber numberWithInt:[startIndex intValue]-1]; // 10.2%
endIndex = [NSNumber numberWithInt:[endIndex intValue]-1]; // 10.5%
}
petalData = [[NSDictionary alloc] initWithObjectsAndKeys:startIndex, @"startIndex", endIndex, @"endIndex", nil]; // 64.4%
[petalsData addObject:petalData]; // 7.7%
[petalData release];
}
int maxLength = MAX(self.frame.size.width, self.frame.size.height);
CGRect petalFrame = CGRectMake((self.frame.size.width - maxLength)/2, (self.frame.size.height - maxLength)/2, maxLength, maxLength);
PetalLayerView *petalLayerView = [[[PetalLayerView alloc] initWithFrame:petalFrame] autorelease];
NSString *tagGroupName = [sectionData objectForKey:@"section_name"];
WheelModel *wheelModel = [WheelModel sharedInstance];
if([sectionData objectForKey:@"filtered"])
{
petalLayerView.outlineColor = [wheelModel.tagColors objectForKey:tagGroupName];
}
petalLayerView.petalColor = [wheelModel.petalColors objectForKey:tagGroupName];
petalLayerView.petalsData = petalsData;
[petalsData release];
return petalLayerView;
}
任何帮助非常感谢!谢谢!
: - 乔
答案 0 :(得分:1)
你确定你在泄漏记忆吗?花瓣数据被petalLayerView保留(大概),所以分配的所有数据都不应该消失(即,它不是泄漏,它是故意分配的)。我认为视图本身可能会被泄露,但这超出了所提供代码的范围。
答案 1 :(得分:-1)
您需要在petalData = [[NSDictionary alloc] ...