是否在window.location重定向之后调用了垃圾收集器? [英] Is the garbage collector called after window.location redirection?

查看:69
本文介绍了是否在window.location重定向之后调用了垃圾收集器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有javascript:

say I have the javascript:

/*getAttribute is mootools method for retrieving a named attribute*/
var companyNumber = button.getAttribute('data-company-number');

var payPoint = button.getAttribute('data-pay-point');

window.location = '/Payslip/ListPayslips/?companyNumber=' + companyNumber + '&payPoint=' + payPoint

delete payPoint;//is this necessary?
delete companyNumber;//is this necessary?

删除行是否必要?他们甚至会被叫吗?

Would the delete lines be necessary? And would they even get called?

推荐答案

要回答第一个问题,是的.卸载时一切都是垃圾(刷新,重定向或关闭时触发卸载).

To answer the first question, yes. Everything is garbage on unload (unload fired on refresh, redirect or close).

要回答第二个问题,重定向后将不会删除该删除项. JS引擎将在那里停止并进行卸载等.

To answer the second question, the deletes will not be hit after the redirect. The JS engine will stop there and fire unload etc.

关于内存管理和显式变量删除的讨论,这里有一些注意事项:

As for the discussion around memory management and explicit variable deletion, here are some considerations:

当开发长时间在浏览器中打开的大型Web应用程序时,尤其是当目标客户端浏览器可以使用旧版本或在较慢的计算机或移动设备上运行时,良好的内存管理就变得很重要.

Good memory management can become important when developing larger web apps that are left open in browser for long periods of time, especially when the target client browsers can be older or on slower machines or mobile devices.

在这种情况下,您声明变量以保存临时信息,特别是大对象,则可以选择删除这些变量以释放它们以进行垃圾回收.我认为,如果不需要新声明,则应避免使用新声明,并在可能的地方重新使用对象-但也许不以牺牲可读性为代价;)

In these cases, where you declare variables to hold temporary information, particularly large objects, you may choose to delete these to free them up for garbage collection. It is my opinion that you should avoid new declarations if they are not necessary and re-use objects where you can - but perhaps not at the expense of readability ;)

要添加到'Corey Ogburn'的观点,删除本身不会释放内存,但是会断开变量与其值的连接.正是这样释放了变量以进行垃圾回收.

To add to 'Corey Ogburn's point, delete itself does not free memory, but disconnects a variable from it's value. It is this that frees the variable for garbage collection.

这篇关于是否在window.location重定向之后调用了垃圾收集器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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