Solve memory leak problem