首页 > 解决方案 > JS中变量的值是否保存在内存堆中

问题描述

我正在学习 JavaScript 并想了解内存分配在该语言中是如何工作的,因此我遇到了内存堆这个术语,它是保存数据的位置。问题是:

任何类型的值(无论是简单的数字还是巨大的数据结构)都只保存在内存堆中,这是真的吗?

标签: javascriptmemory-managementheap-memory

解决方案


The term, "heap," generally refers to an area of memory where things of arbitrary size and purpose are kept, and from which storage is dynamically allocated and released as needed. JavaScript makes extensive use of this for everything it does: variables come into existence for a time, then go away. You can create objects and simply forget about them. Periodically, a "garbage collector" runs through and reclaims things that are no longer actively referenced. All of this sort of thing is what is commonly referred to as "a heap."


推荐阅读