我使用分配分析了我的一个应用程序,发现每当我调用特定方法时,我的“实时字节”量就会增加 300 KB。我不知道是什么原因造成的。
下面这行代码是罪魁祸首:
CNTile *newTile = [self getTileAtPosition:3];
相关方法如下所示:
- (CNTile *)getTileAtPosition:(int)pos
{
CNTile *tileToReturn;
for (int x = 0; x < [row count]; x++)
{
for (int y = 0; y < [col count]; y++)
{
The code here generates four CGPoints and a CGMutablePathRef,
then uses CGPathContainsPoint to determine which CNTile to return.
}
}
return tileToReturn;
}
我应该提到我的 CNTile
类仅包含 UIView
和 UIImageView
,以及一些简单的变量(例如 int
和 BOOL
s)。
如有任何帮助,我们将不胜感激!
最佳答案
如何创建CGMutablePathRef
?使用CGPathCreateMutable?如果是,请确保使用 CGPathRelease 来释放它:
CGMutablePathRef thePath = CGPathCreateMutable();
...
CGPathRelease(thePath);
关于iOS - 什么是分配泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14626605/