Fix a memory leak when the view selection changes.