added memory leak detection