Implemented memory_free function