Fix #267 Cleanup memory ptr frees

- add delete allocated ptr
- use __delete() to free allocated memory

~~*Please do not merge before #439*~~