fixed memory leak when closing