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
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
320
web-secure-phpcon2020
ariaki
3
3.6k
オブジェクトライフサイクルとメモリ管理を学ぼう / OOC 2020
ariaki
8
3.9k
エンジニアはアウトプットによって成長できるのか? / Grow with your output
ariaki
24
6.6k
アウトプットを始めよう / How to begin output jawsug-bgnr
ariaki
2
4k
参加者の安全を守れていますか? / Protecting community safety
ariaki
1
7.4k
タピオカに学ぶ二段階認証 / tapioca-mfa
ariaki
5
1.3k
古に学ぶ個人開発のススメ / My recommendation of personal development
ariaki
1
1.5k
Other Decks in Technology
See All in Technology
『君の名は』と聞く君の名は。 / Your name, you who asks for mine.
nttcom
1
140
_第4回__AIxIoTビジネス共創ラボ紹介資料_20251203.pdf
iotcomjpadmin
0
170
20251203_AIxIoTビジネス共創ラボ_第4回勉強会_BP山崎.pdf
iotcomjpadmin
0
170
Oracle Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
3
240
[PR] はじめてのデジタルアイデンティティという本を書きました
ritou
0
680
Autonomous Database - Dedicated 技術詳細 / adb-d_technical_detail_jp
oracle4engineer
PRO
5
12k
re:Invent2025 セッションレポ ~Spec-driven development with Kiro~
nrinetcom
PRO
2
160
Oracle Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
2
590
さくらのクラウド開発ふりかえり2025
kazeburo
2
1.3k
Agentic AIが変革するAWSの開発・運用・セキュリティ ~Frontier Agentsを試してみた~ / Agentic AI transforms AWS development, operations, and security I tried Frontier Agents
yuj1osm
0
170
Kiro を用いたペアプロのススメ
taikis
4
2.1k
モダンデータスタックの理想と現実の間で~1.3億人Vポイントデータ基盤の現在地とこれから~
taromatsui_cccmkhd
2
290
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
39
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.2k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
The Curse of the Amulet
leimatthew05
0
6.5k
Documentation Writing (for coders)
carmenintech
77
5.2k
Optimizing for Happiness
mojombo
379
70k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Done Done
chrislema
186
16k
The Spectacular Lies of Maps
axbom
PRO
1
410
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Designing Powerful Visuals for Engaging Learning
tmiket
0
190
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
120
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 まとめ