Lesson 2 · Unit 03
Leaks
Memory that is no longer needed but can still be reached
What you practise
- A cache that only grows, listeners never removed, references that keep objects alive
- Reading a memory graph over time
Try a question from this lesson
Pick one
A server does the same amount of work every hour. Its memory use over one day is below. What does this suggest?
hour memory
0 200 MB
6 380 MB
12 560 MB
18 740 MB
24 920 MBCorrect answer
A leak: something keeps data it no longer needs
Why
Steady work should need steady memory. A straight climb of 30 MB an hour means each hour leaves something behind that is never released. Restarting hides the problem; it does not explain it.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Leaks with a garbage collector
The garbage collector frees a value only when nothing can reach it any more.
So in a garbage-collected language a leak is memory the program no longer needs but still refers to: from a global, a cache, a list of listeners, a closure.
The collector cannot know you are done with it. As far as it can tell, you might use it tomorrow.
Fixing a leak always means the same thing: find the reference that keeps the data alive, and drop it.
11 more exercises in the app
- 3× type the answer
- 4× multiple choice
- 1× fill the blanks
- 1× true or false
- 1× match the pairs
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.