solve the memory leaking problem