I use NSMutableData objects to store lists of 32 byte structs that represent series data. These series are potentially extended, added, aligned, etc. To save allocation of unnecessary objects I try to extend and append bytes to existing objects rather than allocate new ones.
I noticed some strange behavior in the simulator today: 1) using setLength and increaseByLength didn’t always zero all new bytes and 2) use of these objects after modification resulted in crashes. The crashes were all in very different areas but always EXC_BAD_ACCESS. After quite a bit of debugging I ended up allocating new objects for working with via mutableCopy and assigning them to my object attributes when done. That solved all of the issues I was having.
* I am working with these objects in background threads but have wrapped all operations in a synchronized block and have not been able to observe any race conditions on the objects in question.
Has anyone noticed similar oddities?
Thanks.
I haven’t received an answer for this so I thought I’d follow up with my solution. I ended up reallocating new NSData / NSMutableData objects as I need them and working with the memory directly before wrapping it in NSData objects.