Fixed memory leak in `while' method