fixed memory leaks in runtime