2012-07-13 1 views
0

메모리에서 힙샷을보고 있습니다. 이 기능은 버려진 메모리의 주범 인 것처럼 보입니다.이것은 버림받은 메모리를 유발합니까?

내보기 중 하나 인 '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]; 

} 
+0

하위보기를 다시 제거 하시겠습니까? 아니면 하나의 하위보기를 계속 추가 하시겠습니까? 이 메서드 내에서 bezierviewImage를 만들고 addSubView가이를 유지합니다. ReleaseFromSuperview는 메모리 할당 측면에서도이를 해제합니다 (즉, 보유 수를 1 씩 줄임). –

+0

Bah! 내 프로젝트의 99 %가 호를 사용합니다. 'MyView'는 그렇지 않은 1 %입니다. 나는 석방하지 않았다. 감사합니다 – dubbeat

답변

1

bezierImageview는 하위 뷰에 추가하기 전에 오토 릴리즈 또는 하위 뷰에 추가 한 후에 해제한다. 해당 객체의 보유 수는 현재 코드로 1을 넘을 수 없습니다.

이것은 ARC가 아닌 것으로 가정하지만 ARC를 사용하는 경우 누설되지 않습니다. 당신이 자동 참조 카운팅 (ARC)를 사용하지 않는 경우

UIImageView *bezierImageView=[[UIImageView alloc]initWithImage:bezierimage]; 

, 당신은 방법이 끝나기 전에 bezierImageView를 autorelease를해야한다 : 당신은, 사실,이 라인에 뭔가의 "소유권 가져 오기"하는

+0

내 질문 아래 내 당황 코멘트를 참조하십시오. 감사합니다 – dubbeat

+0

내 프로젝트의 1 %가 ARC를 사용하므로, 켜지지 않았다고 생각합니다. 또한 당혹 스러울 수 있습니다. – Mark

0

.