added wrapping calls to memory handling in order to implement garbage collection