A Caution on Using Streaming Pointers
Take special caution when dealing with streaming pointers. The Serial package cannot determine what kind of memory a pointer points to, and cannot determine when, or if, it is safe to delete that memory. For this reason, you need to manually manage the memory associated with pointers before streaming into them.
NOTE: The Serial package does not manage the memory associated with streaming pointers. To avoid a memory leak, you must manually manage the memory associated with pointers before and after streaming into them.
In particular, before streaming into a pointer, ensure that the pointer is not the only reference to a heap-allocated block of memory. If it is, the pointer value will be overwritten when the serialized pointer is streamed in, and the only reference to the heap memory will be lost. This will result in a memory leak as well as other potentially unexpected behavior.
After the pointer object has been streamed in, ensure that any memory allocated by the stream is deallocated appropriately. A streamed null pointer will set the pointer's value to 0 when it is streamed in.