简体   繁体   English

IE9中的JavaScript对象终结器

[英]JavaScript object finalizer in IE9

Is there any possibility to execute some custom js code when some object instance is going to be collected by GC in IE9? 当IE9中的某些对象实例将被收集时,是否有可能执行一些自定义js代码? Maybe DOM nodes can afford this functionality somehow? 也许DOM节点能以某种方式提供这种功能?

I'm trying to build some interop library and need to find a way of controlling object instances lifetimes... 我正在尝试构建一些互操作库,需要找到一种控制对象实例生命周期的方法......

Not to the best of my knowledge. 不是我所知道的。 But you can fake it. 但你可以假装它。

One approach is to manually implement a disposal method on each of your JavaScript objects, and have each object dispose all of its members when it is disposed. 一种方法是在每个JavaScript对象上手动实现一个处理方法,并让每个对象在处置它时处理其所有成员。 It does mean you'll have disposed object instance shells lying around before garbage collection, but as long as you're diligent about disposing instances it gives you reasonable resource management. 它确实意味着你将在垃圾收集之前放置对象实例shell,但只要你努力处理实例,它就会为你提供合理的资源管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM