当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JS中关于对内存的释放问题[待续]

Javascript
JavaScript 解析Json字符串的性能比较分析代码
js 日期字符串截取分割成单个具体的日期(2009-12-30 13:28:29)
javascript 倒计时代码
javascript 语法基础 想学习js的朋友可以看看
javascript获取元素文本内容的通用函数
javascript 动态设置已知select的option的value值的代码
jquery 简单的图片展示效果
js textarea自动增高并隐藏滚动条
Javascript 中介者模式实例
textbox 在光标位置插入字符功能的js实现(兼容ie,firefox)
jQuery Attributes(属性)的使用(二、类篇)
Javascript document.referrer判断访客来源网址
[原创]javascript 移动鼠标得到单元格所在table表中的rowIndex位置[兼容ie,firefox]
javascript获得光标所在的文本框(text/textarea)中的位置
event.srcElement 用法笔记e.target
javascript 导出数据到Excel(处理table中的元素)
javascript DOM操作之动态删除TABLE多行
Javascript在IE或Firefox下获取鼠标位置的代码
Javascript 多浏览器兼容性问题及解决方案
让div层随鼠标移动的实现代码 ie ff

Javascript 中的 JS中关于对内存的释放问题[待续]


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 268 ::
收藏到网摘: n/a

JScript uses a mark-and-sweep garbage collector with a variety of heuristics used to determine when to run garbage collection. The JScript garbage collector works like this:

1、When the script engine is shut down, garbage is collected.

2、When 256 variants, or more than 64KB of strings, or more than 4096 array slots have been allocated, the garbage collector sets a flag that says collect soon.

3、Whenever a new statement is executed or the script debugger starts, that flag is checked, and if it is set, a collection is done.

There is an undocumented JScript function called CollectGarbage that forces a garbage collection. This is for testing purposes only—do not ship code that calls this function. It is a poor programming practice to write code in JScript that depends on garbage collections being done at particular times. If you need predictable garbage collection, use a language that supports it (like Visual Basic? or VBScript). Note that all of this is the implementation detail of the engine and should not be relied upon because it may change in the future. Note also that the version of JScript supported by Microsoft? .NET will use the .NET Framework garbage collector, a multigenerational mark-and-sweep collector.
And remember, if you want a deterministic-lifetime app, use a deterministic-lifetime language like C++, Visual Basic 6.0, or VBScript; not an indeterministic-lifetime language like JScript, Scheme, or Java. If you're writing a program that depends on being able to have a deterministic object lifetime, JScript is not the right tool for the job. Trying to make it a deterministic-lifetime language will just create headaches down the road.

js的内存管理类似于java的内存管理!你可以参看java的内存管理机制。

释放一个对象所占的内存必须先释放所有对该对象的引用。

但当对象没有被任何变量应用时,browse也不一定释放该对象所占的内存。

CollectGarbage()并不是推荐的方法。

ie最小化时,会进行垃圾回收!