serializing tuples and freeing memory