使用Javascript - 垃圾收集器计时器? [英] Javascript - garbage collector timers?

查看:116
本文介绍了使用Javascript - 垃圾收集器计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在JavaScript垃圾收集定时器的任何想法?
假设我运行下面的脚本,将功能和相关链接范围的变量会
垃圾收集正是在100ms后?或有人缘?

我计算器了解垃圾收集一个线程,还是我有这个问题。
下面是我的问题?


  1. 是否为垃圾回收任务的任何系统定时器运行?

  2. 如果没有,它是基于事件的?意味着如果引用是没有更多的present,垃圾
    集热器将立即回收内存。

     函数call_me(){
    没有给出code - //计算ELAPSED_TIME           如果(ELAPSED_TIME&小于100)
               {
                的setTimeout(call_me,25);
               }
              其他{
               最后呼叫();
              }
    }打给我();



解决方案

每一个用户代理实现不同的垃圾回收。所有的用户代理使用mark-and-sweep在一个周期重复的方法,所以没有即时这件事;当它发生时就会出现这种情况。

每个代理具有不同的阈值和机制,以确定当GC做一通。它不一定是事件驱动(purhaps你可能会说这是基准驱动,事件发起的),肯定不是基于一个计时器。

这超出范围时功能是即时的符合条件的作为垃圾回收,但真的没有告诉何时会发生。

这是真事,从开发商的角度来看,你是不是要思考的问题。没有任何办法阻止或启动GC,或任何迹象表明它发生在所有。看看有关:内存在Firefox中一些有趣的琐事(有一对夫妇半信半疑按钮那里控制的GC)。这就是所有你会得到尽可能去引擎盖下,而数据是不可用的脚本。

Any idea on garbage collector timer in javascript? Suppose i run below script, will function and associated scope chained variable will go for garbage collection exactly after 100ms? Or some margin?

I read one thread about garbage collection in stackoverflow, still i have this question. Below are my questions?

  1. Does any SYSTEM TIMER run for garbage collection task?
  2. If no, is it EVENT based?, means if reference is no more present, garbage collector will reclaim memory INSTANTLY.

    function call_me() {
    //calculate elapsed_time - code not given
    
               if(elapsed_time <100)
               {
                setTimeout(call_me,25);
               }
              else{
               final_call();
              }
    }
    
    call_me();
    

解决方案

Every user agent implements garbage collection differently. All user agents use the mark-and-sweep method on a periodic repetition, so there is no "instantly" about it; it will happen when it happens.

Each agent has different thresholds and mechanisms to determine when the GC does a pass. It isn't necessarily event-driven (purhaps you might say it is benchmark-driven, event-initiated), and certainly not based on a timer.

A function that passes out of scope is instantly eligible for garbage collection, but there's really no telling when it would happen.

This is really something that, from the developer perspective, you are not intended to think about. There isn't any way to stop or start GC, or any indication that it happened at all. Check out about:memory in Firefox for some interesting trivia (and there's a couple of dubious buttons down there to "control" the GC). That's about all you're going to get as far as it goes under the hood, and that data isn't available to scripts.

这篇关于使用Javascript - 垃圾收集器计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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