Fix initialization of memory objects when using api.