GC and malloced NSData

Christiaan Hofman cmhofman at gmail.com
Tue Jul 8 02:24:13 PDT 2008


I've got another question about GC support. The docs say that stuff in  
the malloc zone is not the garbage collectable. However, objects like  
NSData and NSString have initializers to take over possession of  
malloced bytes like -initWithDataNoCopy:length:, and obj-c objects  
generally are collectable. So it would seem to me very well possible  
that those obj-c objects should be able to clean up the data in - 
finalize, no matter where it is. So now I wonder if code like below is  
GC safe. I could not find anything in the docs either way.

char *bytes = (char *)NSZoneMalloc(NSDefaultMallocZone(), sizeof(char)  
* size);
get_data_using_some_c_lib_function(name, buffer, size);
NSData *data = [NSData dataWithBytesNoCopy:buffer length:size];

Thanks,
Christiaan



More information about the MacOSX-dev mailing list