1
在下面的功能我想返回是從NSData
的NSData得到釋放eventhough其used
- 創建當我給選項
freeWhenDone = YES
的UIImage
顯示的從這裏返回是白色圖像UIImage
指針。 當我給選項
freeWhenDone = NO
UIImage
形式返回這裏展示它作爲一個黑色圖像。- 當我通過
rgb_buffer
(char數組)而不是[rgbData bytes]
函數1和函數2正常工作。一切安好。
這是否與ARC有關?
Myfunction
{
char *pu1_out_buffer = malloc(length);
int width, height, stride;
char *rgb_buffer = malloc(BUFFER_LENGTH);
pu1_out_buffer = datafromfile(FILE_PATH) // initialized with some data , not important
/* rgb NSdata created from malloced rub buffer */
NSMutableData *rgbData = [NSMutableData dataWithBytesNoCopy:rgb_buffer
length:(u4_stride * u4_height * 3)
freeWhenDone:YES];
[self function1:pu1_out_buffer
rgb_buffer:(UWORD16 *)[rgbData bytes]
…]
free(pu1_out_buffer);
UIImage *outUIImage = [self function2:rgbData
width:u4_width
height:u4_height
stride:u4_stride];
return outUIImage;
}
出於好奇:爲什麼你需要使用動態內存分配(malloc's)? –
在不知道'function1','function2'的情況下回答爲什麼圖像是白色或黑色是不可能的。 –
不相關但是'pu1_out_buffer = datafromfile(FILE_PATH)'=無效的語法和內存泄漏。 'MyFunction {'也是無效的,除非一個宏,請張貼一個真實的例子。 – Joe