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.8k
タピオカに学ぶ二段階認証 / tapioca-mfa
ariaki
5
1.4k
古に学ぶ個人開発のススメ / My recommendation of personal development
ariaki
1
1.7k
Other Decks in Technology
See All in Technology
re:Invent2026 事前勉強会 歴史と愉しみ方10分LT編
toshi_atsumi
0
150
cdkd (CDK Direct)
gotok365
4
250
AI時代のエンジニアの情報発信〜個人の発信を組織の力に変える〜
ryo_kawamata
1
7.4k
なぜ東京にいる私が、新潟の技術コミュニティを運営するのか by 八雲慎之助
yakumo
0
220
推論基盤と Scale-Up Interconnect の現状と制約から俯瞰する技術動向
markunet
2
830
Building Audio Plugin Ecosystem for Android in 2026
atsushieno
2
160
re:Invent の去年のスケジュールを公開します!
miu_crescent
PRO
0
310
TSKaigi Sendai 2026 - tsgo時代のTypeScript Playgroundはどう動くか
teamlab
PRO
0
110
【dbts2026】AIエージェントの 判断と探索を変える、 データベース エンジニアリング― 既存DBの処理と依存関係から作る、オペレーショナルオントロジー ―
shisyu_gaku
0
210
新米を「売り越さない」、Aurora DSQLで作る在庫ゼロ死守の限定ドロップEC
yama3133
0
180
AI Agent 時代のデータ基盤: ClickHouse で実現する 超高速分析とコスト削減の両立
jozono
0
200
AIエージェントの監視、思考を見るか行動を見るか / Monitoring AI Agents: Thoughts or Actions
yusukeshimizu
2
170
Featured
See All Featured
Practical Orchestrator
shlominoach
192
12k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
The untapped power of vector embeddings
frankvandijk
2
2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.6k
Code Review Best Practice
trishagee
74
20k
How to Ace a Technical Interview
jacobian
280
24k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
970
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.7k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
760
Unsuck your backbone
ammeep
672
58k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
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 まとめ