how to properly release all memory after use?