Fixed memory leak with clear()