DEV Community

SGsSY
SGsSY

Posted on

The Most Familiar Stranger - JavaScript - Garbage Collection

分享記錄檔 YouTube

JavaScript 會自動分配物件的記憶體位置並在它們不再被使用時清除,清除的這個行為就是 Garbage Collection。

Memory life cycle

  1. 分配記憶體位置
  2. 存取記憶體位置
  3. 當不再使用時釋放記憶體位置

Mark-and-Sweep

遍歷記憶體中所有變數,標記那些仍被使用的變數,沒被標記的就是可以回收的垃圾。

garbage collector 會從 root ( in JS is global object ) 出發,找到所有引用根的物件,再找到引用這些物件的物件,以此類推,將找到所有可到達的物件,並找出那些不可到達的物件。

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay