2012-03-08 2 views
1

프로젝트를 ARC로 변환했으며 누수 계측기에서이 기능은 반복적으로 누출로 태그가 지정됩니다.ARC 누출 기능

나는 objc_release가 해결책일지도 모른다고 생각했지만 xCode는 그것을 좋아하지 않는다. 함수 내에서 호출

- (int)getNumber{ 
int result = 0; 



unsigned char *myBytes = (unsigned char *)malloc(sizeof(char)); 
[stream getBytes:myBytes range:NSMakeRange(0, sizeof(char))]; 

char tag = myBytes[0]; 

if((int)tag >= 0){ 

    result = (int)tag - 64; 
} 
else if ((int)tag == -64) { 

    [self removeChar]; 

    result = [self getInt]; 


} 
else 
{ 

    [self removeChar]; 
    unsigned char *byteTwo = (unsigned char *)malloc(sizeof(char)); 
    [stream getBytes:byteTwo range:NSMakeRange(0, sizeof(char))]; 
    char twoTag = byteTwo[0]; 

    result = 
    ((((int)tag & 0x03f) << 8) | 
    (twoTag & 0x0ff)) ; 
    result -= 8192; 

} 

return result; 

}

두 기능은

- (void)removeChar{ 
[stream replaceBytesInRange:NSMakeRange(0, 1) withBytes:NULL length:0]; 

}

- (int)getInt{ 
NSRange intRange = NSMakeRange(0,3); 

char buffer[4]; 
[stream getBytes:buffer length:4]; 

[stream replaceBytesInRange:intRange withBytes:NULL length:0]; 


return (int) (
       (((int)buffer[0] & 0xff) << 24) | 
       (((int)buffer[1] & 0xff) << 16) | 
       (((int)buffer[2] & 0xff) << 8) | 
       ((int)buffer[3] & 0xff)); 

}이다

+2

'malloc'없이'free'? 그건 누출처럼 보입니다 ...하지만 내가 이해하지 못하는 뭔가가있을 수 있습니다. 정적 분석기는 무엇을 말합니까? – matt

답변

3

당신은 내 바이트와 바이트를 없애 버릴 수 있습니까? 아크가 그 수준에서 메모리 관리를 다루지 않는다는 것은 나의 이해이다.

LLVM Arc

+1

예, ARC는'malloc()'을 사용하지 않습니다. –

+0

감사합니다. teamaxe - 무료 (myBytes) 및 무료 (byteTwo)가 모든 것을 정리했습니다. 누수가 없어지지 않습니다! –