Fixed memory leak for function dispose