Generic Memory Management Flashcards

1
Q

What is a cell? What does it mean to be live?

A
  • any data item in the heap
  • it is live if something else if pointing at it (in a root) not live would be collected by Java’s garbage collector
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a root?

A

registeres, stack locations, global/static variables

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

What is garbage?

A

a block of heap memory that cannot be accessed by the program (not live and nothing points to it, we can’t access it)

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

What is garbage collection?

A
  • automatic management of dynamically allocated storage
  • it is an ADT we can use to allocate memory for objects and clean up that memory when we are done with it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When do you want to call garbage collection?

A
  • Whenever a pointer is set to NULL
  • when there is no memory left
  • at predetermined times

It needs to know which objects are still in use and which are no longer in use

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

What is a buffer?

A

Is a block of “generic” memory, that can be used to store any kind of object. It is up to the programmer to cast the buffer to the required type

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

What are the generic memory management routines and what do they do?

A
  • memcpy: copy memory from one buffer to another
  • memcmp: compare two buffers of memory
  • memset: set a buffer to a specified value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is reference counting and why is it a bad garbage collecting technique?

A
  • it counts the nubmer of references to a cell.
  • the problem is that two cells can reference each other and not have a root(meaning they are garbage) and still be kept by the garbage collector
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the mark-sweep algorithm and in gerneral, how does it work?

A
  • Each cell has a mark bit
  • GC goes to work when the heap is used up, then the program is suspended

Two phases

  1. Marking phase
    • starting from the roots, set the mark bit on all live cells
  2. Sweep phase
    • return all unmarked cells to the free list
    • reset the mark bit on all marked cells
How well did you know this?
1
Not at all
2
3
4
5
Perfectly