ARC泄漏功能

时间:2012-03-08 16:01:38

标签: objective-c memory-leaks automatic-ref-counting

将项目转换为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) );

}

1 个答案:

答案 0 :(得分:3)

你有没有摆脱myBytes和byteTwo?据我所知,Arc不会在那个级别处理内存管理?

LLVM Arc