fix: Ensure DocumentContentSynchronizer is always disposed#1425
fix: Ensure DocumentContentSynchronizer is always disposed#1425angelozerr merged 1 commit intoredhat-developer:mainfrom
Conversation
|
Thanks so much @eliseevh ! Let me try your PR |
| if (synchronizer != null) { | ||
| synchronizer.getDocument().removeDocumentListener(synchronizer); | ||
| synchronizer.dispose(); | ||
| Disposer.dispose(synchronizer); |
There was a problem hiding this comment.
Why you have removed removeDocumentListener ?
There was a problem hiding this comment.
Because I changed call to addDocumentListener, so it would be automatically removed when synchronizer is disposed (it is important to call Disposer.dispose instead of directly calling dispose method on synchronizer). This way, document listener would be also removed if synchronizer is disposed in other places
There was a problem hiding this comment.
I am sorry I don't understand very well.
document.addDocumentListener(synchronizer, synchronizer); is done but what about
document.removeDocumentListener(synchronizer);
You mean that line code Disposer.dispose(synchronizer); will remove synchronizer from document listener?
There was a problem hiding this comment.
Yes. addDocumentListener(Document listener, Disposable) docs says that when second argument is disposed, it will remove document listener (you can look into implementation, it is probably something like addDocumentListener(listener); Disposer.register(disposable, () -> removeDocumentListener(listener));)
And if you register some disposable with Disposer.register(parent, child), when parent is disposed with Disposer.dispose, it will automatically dispose child, so it will remove document listener
|
Thanks so much @eliseevh ! |


Fixes #1360