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.2k
アウトプットの始め方/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
開発投資の期待値を上げるプロダクトロードマップづくり ~プロダクトエンジニアが越境して事業を伸ばす~
kekekenta
1
220
AI時代の「技術的負債」の変質ー概念の終焉と再解釈、エージェントと共に向かう先
nwiizo
1
2.9k
映像変換サーバーなしで端末内でHLSを生成してライブ配信
hikarusato
0
130
株式会社シーエーシー エンジニア向け会社紹介資料
cac
0
57k
AIエージェントの一手は 誰も見ていない - Falco拡張OSS「Prempti」とeBPFで サーバーレス実行基盤を二層防御する
keitah
0
220
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
29
16k
Cloudflare Workers 向けアプリを C# で構築する ~WASM Native AOT への道~
nenonaninu
1
430
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
2.1k
銀行勘定系システムにおける開発プロセス刷新×AIによる環境モダナイゼーション / Development Process Transformation and AI-Driven Environment Modernization
muit
1
2.3k
AIで社員の自主発信に広報目線を組み込む
_mossann_t
0
130
The Knowledge Spine: A Machine-Executable Ontology for Governed Marketing Activation
vananth22
0
110
山手線を徒歩で一周してわかった、 位置情報アプリは「足」が最強のデバッガー
hinakko
0
170
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
830
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
730
A designer walks into a library…
pauljervisheath
211
25k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
520
Into the Great Unknown - MozCon
thekraken
41
2.7k
Paper Plane
katiecoart
PRO
4
53k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Leo the Paperboy
mayatellez
10
2.3k
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 まとめ