Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
How GC works in JavaScript engine
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Akira Morikawa
June 26, 2018
Technology
5
530
How GC works in JavaScript engine
GCタイミングを理解するために、オブジェクト生存期間とスコープについて簡単に説明します。
Akira Morikawa
June 26, 2018
Tweet
Share
More Decks by Akira Morikawa
See All by Akira Morikawa
コロナ禍だからこそ考えるオフラインコミュニティの意義 / significance of community
ariaki
0
2k
アウトプットの始め方/start output 20230121
ariaki
0
330
web-secure-phpcon2020
ariaki
3
3.6k
オブジェクトライフサイクルとメモリ管理を学ぼう / OOC 2020
ariaki
8
3.9k
エンジニアはアウトプットによって成長できるのか? / Grow with your output
ariaki
24
6.7k
アウトプットを始めよう / How to begin output jawsug-bgnr
ariaki
2
4k
参加者の安全を守れていますか? / Protecting community safety
ariaki
1
7.5k
タピオカに学ぶ二段階認証 / tapioca-mfa
ariaki
5
1.3k
古に学ぶ個人開発のススメ / My recommendation of personal development
ariaki
1
1.5k
Other Decks in Technology
See All in Technology
セキュリティについて学ぶ会 / 2026 01 25 Takamatsu WordPress Meetup
rocketmartue
1
150
20260129_CB_Kansai
takuyay0ne
1
240
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
66k
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
2.9k
ZOZOにおけるAI活用の現在 ~開発組織全体での取り組みと試行錯誤~
zozotech
PRO
3
1.9k
15 years with Rails and DDD (AI Edition)
andrzejkrzywda
0
110
Databricks Free Edition講座 データサイエンス編
taka_aki
0
250
M&A 後の統合をどう進めるか ─ ナレッジワーク × Poetics が実践した組織とシステムの融合
kworkdev
PRO
1
140
VRTと真面目に向き合う
hiragram
1
520
Deno・Bunの標準機能やElysiaJSを使ったWebSocketサーバー実装 / ラーメン屋を貸し切ってLT会! IoTLT 2026新年会
you
PRO
0
180
新規事業における「一部だけどコア」な AI精度改善の優先順位づけ
zerebom
0
440
AI開発の落とし穴 〜馬には乗ってみよAIには添うてみよ〜
sansantech
PRO
10
5.6k
Featured
See All Featured
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
87
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
150
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
440
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
630
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
120
Mobile First: as difficult as doing things right
swwweet
225
10k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
55
49k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
61
Game over? The fight for quality and originality in the time of robots
wayneb77
1
91
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Transcript
How GC works in JavaScript engine 2018-06-26 @ Roppongi.js #4
ariaki
None
← Allocated Memory Block
None
Out Of Memory
rbage Correction G
GC: Mark And Sweep 1. 到達可能なオブジェクトにマークする (Mark Phase)
2. 不要と判断した領域を回収する (Sweep Phase) GC: Mark And Sweep
GC: Mark And Sweep - Incremental GC - Stop-the-World しない
- Write Barrier - Memory Fence - Concurrent Marking - Parallel Marking - V8 v6.4 (Chrome 64) でかなり高速化した https://v8project.blogspot.com/2018/06/concurrent-marking.html
bject Lifecycle
Q1:どんな結果になるでしょう?
A1: (1) a=null (2) b=Tue Jun 26 2018 20:00:00 GMT+0900
(日本標準時)
【解説】 new Date() Memory var a ( Reference Counter =
1 )
【解説】 Memory var a ( Reference Counter = 2 )
var b
【解説】 Memory var a ( Reference Counter = 1 )
var b ← 到達可能
【解説】 Memory var a ( Reference Counter = 0 )
var b ← 到達不能
Q2:どんな結果になるでしょう?
A2: (1) a=undefined (2) b=Tue Jun 26 2018 20:00:00 GMT+0900
(日本標準時)
Q3:以下のオブジェクトは到達不能?
A3: オブジェクトは到達可能
【解説】 inner x inner y var a var b var
tmp
【解説】 inner x inner y var a var b var
tmp
Q4:以下のオブジェクトは到達不能?
A4: オブジェクトは到達不能
【解説】 var a var b window
【解説】 var a var b window
Q5:GCされないオブジェクトはいくつ?
A5:5つ
【解説】 Javascriptでは「関数オブジェクト」なので忘れやすい。
ローカルスコープの変数に代入は不要 ※代入コストがかかるため 書かないことを推奨 【解説】
【解説】
その他 ※for 文で回す方が大抵 gc よりも低コストになる
その他
- GC: Mark And Sweep - GC は手動実行できない - root
からの到達可能性をチェック - なるべくGCさせない事を意識する - 不要なオブジェクトを生成しない ← タイミングを知る - スコープに注意する - 関数内 var はローカルスコープ - var 指定なしはグローバルスコープ - const / let はブロックスコープ (ES6) - GC対象にするためには - Object に対しては null - Object.property に対しては delete まとめ