use PyMem, add memory deallocation