FROM : Michael Tsai
DATE : Wed Feb 06 17:46:25 2008
On Feb 6, 2008, at 10:55 AM, Alastair Houghton wrote:
> I'll just add, publicly, that I think this probably is a bug in
> CFString that John has found here. That is, I don't see why
> CFString's pointer shouldn't be traced by the collector in this
> case (it doesn't appear to be; certainly when I try it the backing
> buffer is released). The problem also occurs with NSString's -
> initWithBytesNoCopy:length:encoding:freeWhenDone: et al.
I don't think this is a bug. The NSString and CFString APIs do not
indicate that they treat the bytes as scanned memory. In fact, when
you pass in kCFAllocatorNull you are telling CFString that you
"assume responsibility for deallocating the buffer." At the end of -
someMethod, you haven't saved a __strong reference to the buffer, so
the collector is allowed to free it.
--Michael
DATE : Wed Feb 06 17:46:25 2008
On Feb 6, 2008, at 10:55 AM, Alastair Houghton wrote:
> I'll just add, publicly, that I think this probably is a bug in
> CFString that John has found here. That is, I don't see why
> CFString's pointer shouldn't be traced by the collector in this
> case (it doesn't appear to be; certainly when I try it the backing
> buffer is released). The problem also occurs with NSString's -
> initWithBytesNoCopy:length:encoding:freeWhenDone: et al.
I don't think this is a bug. The NSString and CFString APIs do not
indicate that they treat the bytes as scanned memory. In fact, when
you pass in kCFAllocatorNull you are telling CFString that you
"assume responsibility for deallocating the buffer." At the end of -
someMethod, you haven't saved a __strong reference to the buffer, so
the collector is allowed to free it.
--Michael






Cocoa mail archive

