Should I destroy JSON object when navigating to different page on SPA

喜夏-厌秋 提交于 2019-12-13 03:39:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!