handle memory leakage