Bitpath

Lesson 2 · Unit 03

Leaks

Memory that is no longer needed but can still be reached

13 exercisesabout 3 min

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 MB

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.

One email when Bitpath is ready to try. Nothing else. Privacy