Reduce memory leaks from nodes remaining after new document is painted.