我在看内存中的堆镜头。这个功能似乎是废弃记忆的罪魁祸首。这是造成遗弃的记忆?
它是我的一个视图'MyView'的视图构建代码的一部分。
如果我用这个函数创建并销毁'MyView'100次,那么注释的内存大小总是返回到它的基线。但是,如果我在我的记忆中留下这个功能不断增加。
据我所见,我不会取得该功能中的任何东西的所有权。 我在做什么错?
-(void)drawPointAroundCircle:(CGPoint)centerpoint radius:(int)radius amount:(int)amount
{
CGPoint pointarray[amount];
float thetaarray[7]={270.0,315.0,0.0,45.0,135,180.0,225.0};
int i=-1;
UIGraphicsBeginImageContext(CGSizeMake(self.frame.size.width,self.frame.size.height));
CGContextRef context=UIGraphicsGetCurrentContext();
for (i=0; i<7; i++) {
float x=cosf(D2R(thetaarray[i]))*radius;
float y =sinf(D2R(thetaarray[i]))*radius;
x=x+centerpoint.x;
y=y+centerpoint.y;
pointarray[i].x=x;
pointarray[i].y=y;
UIBezierPath *path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(x, y) radius:2 startAngle:D2R(0) endAngle:D2R(360) clockwise:YES];
CGContextSetFillColorWithColor(context, [UIColor grayColor].CGColor);
[path fill];
[path closePath];
}
UIImage *bezierimage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *bezierImageView=[[UIImageView alloc]initWithImage:bezierimage];
[self addSubview:bezierImageView];
}
您是否曾经再次删除子视图或者继续添加一个子视图?在该方法中,您创建bezierviewImage,addSubView将保留它。 ReleaseFromSuperview会根据内存分配释放它(意思是将保留计数减1)。 – 2012-07-13 14:21:53
Bah !!!我的项目中99%使用弧线。 'MyView'是没有的1%。我从未称呼释放。谢谢 – dubbeat 2012-07-13 14:32:10