Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
How GC works in JavaScript engine
Search
Akira Morikawa
June 26, 2018
Technology
550
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How GC works in JavaScript engine
GCタイミングを理解するために、オブジェクト生存期間とスコープについて簡単に説明します。
Akira Morikawa
June 26, 2018
More Decks by Akira Morikawa
See All by Akira Morikawa
コロナ禍だからこそ考えるオフラインコミュニティの意義 / significance of community
ariaki
0
2.3k
アウトプットの始め方/start output 20230121
ariaki
0
370
web-secure-phpcon2020
ariaki
3
3.8k
オブジェクトライフサイクルとメモリ管理を学ぼう / OOC 2020
ariaki
8
4.2k
エンジニアはアウトプットによって成長できるのか? / Grow with your output
ariaki
24
6.8k
アウトプットを始めよう / How to begin output jawsug-bgnr
ariaki
2
4.1k
参加者の安全を守れていますか? / Protecting community safety
ariaki
1
7.7k
タピオカに学ぶ二段階認証 / tapioca-mfa
ariaki
5
1.4k
古に学ぶ個人開発のススメ / My recommendation of personal development
ariaki
1
1.6k
Other Decks in Technology
See All in Technology
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
3
1.1k
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
290
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
140
AIカンパニーへの転換を支えた、エンジニアの仕事の再定義
kworkdev
PRO
2
1.2k
Optunaの最新リリースv5.0について
pfn
PRO
0
120
フロントエンドカンファレンス関西2026 - 速すぎるUIに、待ち時間を
teamlab
PRO
0
130
Webの常識が通じないHTMLメールのダークモード
teamlab
PRO
0
120
会社説明資料
persolserverworks
0
9.8k
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
170
「Docker Desktop不要の時代」は 来たのか?
ueponx
0
770
Running Kotlin + Quarkus with Lambda
nealle
1
3.7k
AIにシークレットを見せない、WSL2で安全な開発環境
yazm
0
300
Featured
See All Featured
Unsuck your backbone
ammeep
672
58k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Agile that works and the tools we love
rasmusluckow
331
22k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
How to Talk to Developers About Accessibility
jct
2
580
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
940
Six Lessons from altMBA
skipperchong
29
4.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
280
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
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 まとめ