將項目轉換爲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));
}
'malloc' without'free'?這確實看起來像一個泄漏......但也許還有別的事情,我不理解。什麼是靜態分析儀說? – matt 2012-03-08 16:07:59