zoukankan      html  css  js  c++  java
  • garbage collection 垃圾收集 生命周期 跟踪内存使用

    Professional.JavaScript.for.Web.Developers.3rd.Edition.Jan.2012

    JavaScript is a garbage-collected language, meaning that the execution environment is responsible
    for managing the memory required during code execution. In languages like C and C++, keeping
    track of memory usage is a principle concern and the source of many issues for developers.
    JavaScript frees developers from worrying about memory management by automatically allocating
    what is needed and reclaiming memory that is no longer being used. The basic idea is simple: figure
    out which variables aren’t going to be used and free the memory associated with them. This process
    is periodic, with the garbage collector running at specified intervals (or at predefined collection
    moments in code execution).
    Consider the normal life cycle of a local variable in a function. The variable comes into existence
    during the execution of the function. At that time, memory is allocated on the stack (and possibly
    on the heap) to provide storage space for the value. The variable is used inside the function and then
    the function ends. At that point this variable is no longer needed, so its memory can be reclaimed
    for later use. In this situation, it’s obvious that the variable isn’t needed, but not all situations are
    as obvious. The garbage collector must keep track of which variables can and can’t be used so it
    can identify likely candidates for memory reclamation. The strategy for identifying the unused
    variables may differ on an implementation basis, though two strategies have traditionally been used
    in browsers.
     
    //局部变量只在函数执行的过程中存在。而在这个过程中,会为局部变量在栈(或堆)内存上分配相应的空间,以便存储它们的值。然后在函数中使用这些变量,直至函数执行结束。
     
     
     
     
     
     
  • 相关阅读:
    建网站该选择服务器还是虚拟主机
    会计基础第一章模拟试题(3)
    会计基础第一章模拟试题(2)
    13条Android手机必备技巧 让玩机更有趣
    会计基础第一章模拟试题(1)
    会计基础第二次模拟题(6)
    Foxmail邮箱最新应用指南 --如何使用「邮件标签」?
    会计基础第二次模拟题(5)
    如何使用有道云笔记的剪藏功能
    使用JSCH执行命令并读取终端输出的一些使用心得
  • 原文地址:https://www.cnblogs.com/rsapaper/p/5937084.html
Copyright © 2011-2022 走看看