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.

//局部变量只在函数执行的过程中存在。而在这个过程中,会为局部变量在栈(或堆)内存上分配相应的空间,以便存储它们的值。然后在函数中使用这些变量,直至函数执行结束。

时间: 2024-11-10 07:41:05

garbage collection - 垃圾收集的相关文章

Java Garbage Collection/垃圾收集

Java 的垃圾收集有各种各样的策略,默认的策略也会经常的改变. --比如到底是 serial , parallel, CMS; 具体到 Minor 怎么样,Old 又怎么样? 命令 java -XX:+PrintFlagsFinal -version ,提供帮助: bool UseParNewGC = false {product} bool UseParallelGC = false {product} bool UseParallelOldGC = false {product} bool

Java Performance - Garbage Collection/垃圾收集

随着硬件的不断提升,Java Heap 越来越大,合理的垃圾收集调优变得愈发重要.下面介绍一些最佳实践: 注意: 下面不涉及 IBM AIX Java. 同时不介绍原理,仅仅是建议以及初始配置/最佳实践,后续如何迭代优化 需要理解 The Java Virtual Machine Specification  > Run-Time Data Areas 和 Memory Management Whitepaper 配置合适的堆内存大小 通过配置 -Xms -Xmx 设定,分别表示初始和最大值 可

GC(Garbage Collection)垃圾回收机制

1.在垃圾回收器中,程序员没有执行权,只有通知它的权利. 2.程序员可以通过System.gc().通知GC运行,但是Java规范并不能保证立刻运行. 3.finalize()方法,是java提供给程序员用来释放对象或资源的办法,但是尽量少用. 一.GC的介绍 GC的全称是Garbage Collection (垃圾收集) 在GC中,垃圾所指的是程序在运行过程中,会产生出一些无用的对象,或者说是已经被弃用的对象,而这些对象会占用着一部分的内存空间,如果长时间不去回收这些内存空间,那么最终会导致O

java 垃圾回收机制和调优(转)Java Garbage Collection

(转)http://www.cnblogs.com/shudonghe/p/3457990.html 文主要介绍,JVM的组件,自动垃圾收集器是如何工作的,分代垃圾收集器的收集过程,使如何用Visual VM来监视应用的虚拟机,以及JVM中垃圾收集器的种类. 一.JVM架构 1.HotSpot 架构 HotSpot JVM架构支持较强的基本特征和功能,此外还支持高性能和高吞吐率的特性.例如,JVM JIT编译器产生动态优化的代码,亦即,编译器是在Java运行的时候的时候进行优化,并为当然的系统架

深入理解Java中的Garbage Collection

前提 最近由于系统业务量比较大,从生产的GC日志(结合Pinpoint)来看,需要对部分系统进行GC调优.但是鉴于以往不是专门做这一块,但是一直都有零散的积累,这里做一个相对全面的总结.本文只针对HotSpot VM也就是Oracle Hotspot VM或者OpenJDK Hotspot VM,版本为Java8,其他VM不一定适用. 什么是GC(Garbage Collection) Garbage Collection可以翻译为"垃圾收集" -- 一般主观上会认为做法是:找到垃圾,

[Java] 垃圾回收机制 ( Garbage Collection ) 简介

自动垃圾回收( Automatic Garbage Collection ) 自动垃圾回收,是指在堆(Heap)内存上分辨哪些对象还在被使用,哪些对象没有被使用,并清除没有被使用的对象.所以,这里的垃圾实际上是指,在内存中,无法再被使用没有存在的价值的但还占据内存空间的对象. C 语言的内存分配.回收是需要手动完成的,但在 Java 中,回收内存是由垃圾回收器自动完成的. 垃圾回收分为两步骤:1.标记,2.删除.删除垃圾有两种情况,a. 常规删除,b. 带压缩的删除. 第 1 步. 标记 ( M

Advanced .NET Debugging: Managed Heap and Garbage Collection(转载,托管堆查内存碎片问题解决思路)

原文地址:http://www.informit.com/articles/article.aspx?p=1409801&seqNum=4 Debugging Managed Heap Fragmentation Earlier in the chapter, we described a phenomenon known as heap fragmentation, in which free and busy blocks are arranged and interleaved on th

[Java] 垃圾回收 ( Garbage Collection ) 的步骤演示

关于 JVM 垃圾回收机制的基础内容,可参考上一篇博客 垃圾回收机制 ( Garbage Collection ) 简介 上一篇博客,介绍了堆的内存被分为三个部分:年轻代.老年代.永生代.这篇博文将演示这三个部分如何交互,实际也演示了垃圾回收. 1. 首先,所有新创建的对象都会陪分配到年轻代的 Eden 空间,而两个 survior 空间一开始都为空. 下图表示的是运行一段实际后的年轻代内存情况,新创建的对象会被放在 Eden 空间,"from" survior space 里面的数字

Tuning Java Garbage Collection for Spark Applicati

This is a guest post from our friends in the SSG STO Big Data Technology group at Intel. Join us at the Spark Summit to hear from Intel and other companies deploying Spark in production.  Use the code Databricks20 to receive a 20% discount! Spark is