Re: [Q] [NSValue valueWithBytes: objCType:]
Re: [Q] [NSValue valueWithBytes: objCType:]
- Subject: Re: [Q] [NSValue valueWithBytes: objCType:]
- From: Jens Alfke <email@hidden>
- Date: Thu, 31 Jul 2008 13:47:06 -0700
On 31 Jul '08, at 11:37 AM, JongAm Park wrote:
1. Whether the dataDesc is statically declared or not, although it
is freed in the end of the "encode" action handler, it is still
maintained and could be accessed from another message, "recover".
And with the Memory browser, I could confirm that the memory content
was still there. Why is it so? Does the NSData or NSArray just
retains them?
The free( ) call doesn't immediately overwrite the block. It's added
to a free-list and will be reused later in a future malloc( ) call.
However, you can't rely on that of course; accessing any data from a
freed block is a bug that can lead to random crashes.
2. However, when I intentionally bzero it, the content is nullified,
and the recover message sees the content as zeros. So, it is not
caches in the NSArray. It seems to me that it just uses by
referencing.
That's bad. It sounds like the object you create doesn't contain a
copy of the struct but just a pointer to it.
5. for the data, I used dataWithBytes: length: thinking that it will
copy the contents, instead of just referencing the original.
However, it turns out that it just references it. I figured that out
by bzeroing the original, and how it is seen in the recover function.
No, +dataWithBytes: does copy the data. It's only the "...noCopy"
variants that will [possibly] use your existing buffer.
Something's fundamentally wrong with your code, in that data you think
you're copying is really just being referenced through a pointer. I'm
sorry, but you posted a lot of stuff and I'm not going to read through
it all to debug it for you. You need to do some code review on your own.
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden