improve memory initialization and shutdown