The Apple documentation regarding NSData says
NSDataand its mutable subclassNSMutableDataprovide data objects, object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation objects.
What do they mean by “embedded pointers”? My understanding is that once you put bytes into it, it has no idea what it is unless you decode it at the application level. Anyone know what they are talking about?
The purpose of NSData is to provide a means to cleanup an allocated data buffer when it is no longer needed, i.e. when the reference count of NSData goes to 0. In the common case, the data is allocated with malloc and NSData uses a corresponding call to free to deallocate the data. This places a restriction on the nature of the byte data. It must be Plain Old Data. If the data was a struct containing a field which pointed to another region of memory allocated with malloc (an embedded pointer), the embedded pointer would never be freed by the NSData object, resulting in a memory leak. For example: