memory leak test refactoring