2012-09-18 4 views
1

메서드에서 돌아올 때 CoreGraphics로 메모리를 관리하는 데 항상 많은 어려움이있는 것처럼 보입니다. 그것은 다른 곳 곳에서 호출 할 수 있기 때문에, mutablePath을 유지하기 위해 (CGMutablePathRef) mutablePath 이니셜 :CoreGraphics, Memory Deallocation, Return Values ​​

- (id) init 
{ 
    CGMutablePathRef mutablePath = CGPathCreateMutable(); 

    //mutable path gets loaded with some hard data 

    return [self initWithMutablePath:mutablePath]; 
} 

- (id) initWithMutablePath:(CGMutablePathRef)mutablePath 
{ 
    self = [super init]; 

    if (self) 
    { 
     _mutablePath = (CGMutablePathRef) CGPathRetain(mutablePath); 
    } 

    return self; 
} 

암이 악기에서이 메시지를 받고 :

Potential leak of an object allocated on line 38 and stored into 'mutablePath' 

나는 initWithMutablePath을 원하십니까 아래의 상황을 받아 필요할 것입니다. 그러나 init 메서드를 사용하여 mutablePath를 아무런 문제없이 전달할 수도 있습니다. 이것이 어떻게 성취 될 수 있는가?

+0

이유는 CGPathRetain이 원인 일 수 있습니다. CGPathCreateMutable은 유지 상태를 유지하며 CGPathRetain을 다시 사용하는 이유는 무엇입니까? –

+0

@LithuThiruvathira - 네, 생각합니다.하지만 이니셜 라이저는 다른 곳에서 호출해야하므로 어디서나 그렇게해야합니다. –

+0

make CGMutablePathRef mutablePath = CGPathCreateMutable(); if 루프에서 if (mutablepath) initWithMutablePath : 메서드에서 tht를 제거합니다. –

답변

0

내가하려는 것은 불가능하기 때문에 initWithMutablePath (기본 클래스의 생성자)를 없애고 기본 클래스에 생성자를 구현하지 않게되었습니다. 내가 상속 자식 클래스가 초기화 프로그램을 구현하고 경로를로드합니다.