Generic Memory Management Flashcards
What is a cell? What does it mean to be live?
- 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
What is a root?
registeres, stack locations, global/static variables
What is garbage?
a block of heap memory that cannot be accessed by the program (not live and nothing points to it, we can’t access it)
What is garbage collection?
- 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
When do you want to call garbage collection?
- 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
What is a buffer?
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
What are the generic memory management routines and what do they do?
- memcpy: copy memory from one buffer to another
- memcmp: compare two buffers of memory
- memset: set a buffer to a specified value
What is reference counting and why is it a bad garbage collecting technique?
- 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
What is the mark-sweep algorithm and in gerneral, how does it work?
- Each cell has a mark bit
- GC goes to work when the heap is used up, then the program is suspended
Two phases
- Marking phase
- starting from the roots, set the mark bit on all live cells
- Sweep phase
- return all unmarked cells to the free list
- reset the mark bit on all marked cells