Upon loading, VisualEditor removes some DOM nodes to get rid of elements that only make sense for article view (including the article content itself but also gadgets etc). That does not always work (see T120443); also some scripts might have event subscriptions or timeouts they should release, requests to cancel, or maybe they use a lot of memory which they might want to free up. There should be a "content unload" event that such scripts can subscribe to, fired by VE when it removes the content.
(A "content load" event is also needed for when VE is saved / cancelled, BUT AFAIK wikipage.content works for that.)