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 JavaScript Collects Your Garbage
Search
Rory Fitzpatrick
November 13, 2014
Technology
22
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How JavaScript Collects Your Garbage
Rory Fitzpatrick
November 13, 2014
More Decks by Rory Fitzpatrick
See All by Rory Fitzpatrick
Visualising Edinburgh Festivals
roryf
0
35
Other Decks in Technology
See All in Technology
パッチ更新でterraform initが落ちた日
grimoh
1
140
How to Design Configuration for Rails Applications
willnet
1
820
スキマバイトという雇用形態は存在しないので、雇用期間1日のアルバイト契約を事業者とワーカーが結ぶ手続きを支えるのがタイミーなんです
akitoshiga
0
200
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
6
5k
Browser Spec: Testing Hotwire with Ruby
takahashim
1
130
Rust で関数型ドメインモデリング
takonda
0
140
Rustuna: Rustによる高速なOptuna実装
pfn
PRO
0
190
Classmethod Company Deck
satoshi7
1
710
WasmをRustにする
sansantech
PRO
0
260
大型犬好きによるPugの紹介
yamanoku
1
160
自作バイナリを動かす「入口」8選
puhitaku
2
1.3k
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
200
Featured
See All Featured
Fireside Chat
paigeccino
43
4.1k
A designer walks into a library…
pauljervisheath
211
25k
A better future with KSS
kneath
240
18k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
990
Abbi's Birthday
coloredviolet
4
10k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
930
Google's AI Overviews - The New Search
badams
0
1.6k
We Have a Design System, Now What?
morganepeng
55
8.4k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
270
Paper Plane (Part 1)
katiecoart
PRO
2
12k
Transcript
How JavaScript Collects Your Garbage Rory Fitzpatrick EdinburghJS November 2014
What is Garbage Collection?
In computer science, garbage collection (GC) is a form of
automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program. http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)
var foo = {hello: “EdinJS”}; foo = null; // Creates
garbage
Mark and sweep
1 1 1 1 1 1 1 1 1 1
1 1 1
Why do I care?
None
var foo = {hello: “EdinJS”}; var bar = foo; foo
= null; bar = null;
function sayHello(data) { setTimeout(function() { console.log(data.hello); }, 1000); } !
var foo = {hello: “EdinJS”}; sayHello(foo); foo = null;
function sayHello(data) { setInterval(function() { console.log(data.hello); }, 1000); } !
var foo = {hello: “EdinJS”}; sayHello(foo); foo = null;
When does GC run?
Code
DOM leaks
var el = document.getElementById(‘myBtn’); var data = { el: el,
msg: ‘hello’ }; ! el.addEventListener(‘click’, function() { alert(data.msg); }); ! // Some time later ! el.parentNode.removeChild(el); IE<8
delete is good delete myObj.someProperty; ! myObj.someProperty; -> undefined
Hidden classes var data = { foo: “bar” }; !
doSomething(data); delete data.foo;
delete is bad
Always use var
V8 is clever function sayHello(data) { console.log(data.hello); ! setInterval(function() {
console.log(‘interval’); debugger; // console.log(data) -> undefined }, 1000); } ! var foo = {hello: “EdinJS”}; sayHello(foo); foo = null;
JavaScript engines are smart Performance is hard Humans are dumb
Questions / Corrections @roryf github.com/roryf
[email protected]
I am an imposter I love to procrastinate I have
a fear of failure