导航到SPA上的其他页面时是否应该销毁JSON对象 [英] Should I destroy JSON object when navigating to different page on SPA

查看:184
本文介绍了导航到SPA上的其他页面时是否应该销毁JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SPA,可将包含模型数据的HTML和Javascript文件加载到屏幕上.在特定页面加载时,它们的属性可能看起来像这样.该对象可能包含大量的属性和功能.

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();

如果我离开该页面(自从其具有SPA以来就在页面中动态加载新的HTML和Javascript,该属性仍将保持原样.

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.

多年来没有伤害任何人,但我认为销毁它们可能会更好.如果有人回到页面,则仅从动态加载的Javascript文件重新创建该对象.

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?

推荐答案

如果将其设置为undefined的属性,则最终应该对数据进行垃圾收集.如果用户在关闭浏览器之前返回页面,只需确保重新初始化属性即可.

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.

这篇关于导航到SPA上的其他页面时是否应该销毁JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆