Fixed memory leaks on window closing.