Garbage Collection (L13) Flashcards

1
Q

Which type of memory allocation must be explicitly handled by the programmer (or by GC)?

A

Dynamic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a memory leak?

A

Failure to reclaim unused, previously dynamically
allocated memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the most fundamental, two phase garbage collection technique called?

A

Mark and sweep.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are tracing collectors?

A

These are a class of garbage collectors that identify/reclaim unreachable objects by tracing the program’s execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the root set?

A

It is the initial set of objects that are directly accessible and serve as the starting point for marking all other reachable objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What types of variables make up the root set?

A

Any global variables, and variables/references on the current call stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the mark phase of the mark and sweep algorithm.

A

Starting from the root set, all accessible objects in memory are looked at and marked as “in use” by setting a flag (if in use).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When are in use flags cleared?

A

At the start of a GC cycle (prior to mark phase).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe the sweep phase of the mark and sweep algorithm.

A

The GC cycles through all objects in the heap and, if their flags aren’t set, reclaims their memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Does GC run continuously?

A

No, since it steals processing cycles away from the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the most common strategy for choosing to invoke the garbage collector?

A

When memory is low.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can the GC be invoked on a predefined schedule?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In practice, when do (naive) mark and sweep algorithms begin to fail?

A

In large applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the tri colour approach?

A

GC in which candidates for reclamation are iteratively moved between three sets until it is certain that they are no longer required.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the generational technique?

A

GC in which the age of objects impacts the frequency of testing - older objects are likely long term and thus considered less.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Is it possible to provide GC for languages like C?

A

Yes, using an external collector that the compiler does not need to directly support.

17
Q

Name an external GC that can be used by C?

A

Boehm GC.

18
Q

What algorithm does the Boehm GC use?

A

Mark and sweep.

19
Q

The Boehm GC is considered a black box, meaning what?

A

It is not integrated into the C compiler.

20
Q

The Boehm GC is conservative, meaning what?

A

It may have false negatives (items that could be reclaimed, but aren’t), but never has false positives (never reclaims items that shouldn’t be).

21
Q

Which function call does the BGC replace with its own version?

A

Stadard malloc calls - functionality remains the same, but BGC maintains additional information about all dynamically allocated memory.

22
Q

What memory regions are monitored by the BGC?

A

The stack frame and static region.

23
Q

BGC knows a word sized value on the stack isn’t a pointer value if it cannot be interpreted as what kind of address?

A

As a valid heap address.

24
Q

How do transient memory leaks occur?

A

Transient memory leaks occur when BGC interprets non-address values on the current stack frame as valid pointers.

25
Q

Why are transient memory leaks considered transient?

A

Transient as in temporary, and temporary because the memory leak is rectified once the stack frame ends.

26
Q

Why are transient memory leaks not common on modern 64 bit systems?

A

Because the heap represents a tiny portion of the total process space - it is thus unlikely for random sequences of bits to present a valid pointer.

27
Q

Why do performance sensitive systems use manual collection over GC?

A

Manual collection is faster and more predictable.

28
Q

What GC method does Python implement?

A

Reference counting.

29
Q

Describe reference counting.

A

References/assignments are kept track of, the memory they point to is reclaimed when none are left.

30
Q

Why are the issues with reference counting?

A

Cyclic references are difficult to detect, and lots of overhead due to constant count updates.

31
Q

Does reference counting fall under the umbrella of tracing collectors?

A

No.