Partial cleanup: freeing memory on close