Fix IllegalReferenceCountException which occurs when multipart data is stored in memory

- Fixes #2102