问题
I have a SPA which loads the screen with HTML and Javascript files that contain the model data. They property could look like this on a specific page load. The object could contain a large number of properties and functions.
app.viewModel.members.eventSchedule = new EventSchedule();
If I navigate away from the page (load new HTML and Javascript dynamically in the page since its an SPA, the property is still there intact.
It hasn't hurt anything for years but I think it may be better to destroy them. If someone comes back to the page, the object just gets recreated from the Javascript file that dynamically loads.
Should I destroy these objects by navigating away from the page or keep them and what is the best way to do it and where?
回答1:
If you set it to properties to undefined, the data should eventually be garbage-collected. Just be sure to reinitialize the properties if the user returns to the page before closing the browser.
来源:https://stackoverflow.com/questions/52266089/should-i-destroy-json-object-when-navigating-to-different-page-on-spa