메모리에서 힙샷을보고 있습니다. 이 기능은 버려진 메모리의 주범 인 것처럼 보입니다.이것은 버림받은 메모리를 유발합니까?
내보기 중 하나 인 '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 씩 줄임). –
Bah! 내 프로젝트의 99 %가 호를 사용합니다. 'MyView'는 그렇지 않은 1 %입니다. 나는 석방하지 않았다. 감사합니다 – dubbeat