FlashKeepers

Programming Concepts · College · College and University

Garbage Collection and Memory Management

Stack versus heap, reference counting, mark and sweep, generational GC, manual management, leaks and fragmentation.

About this set

35 basic cards for College Programming Concepts. It opens with "What is the stack in memory management?" and "What does LIFO mean in the context of the stack?". Study it alongside the other College sets below.

35 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is the stack in memory management?
Show answerA region of memory that stores local variables and function call information, following LIFO order.
What does LIFO mean in the context of the stack?
Show answerLast In, First Out - the most recently added item is removed first.
When are stack variables automatically freed?
Show answerWhen the function they are declared in returns or exits its scope.
What causes a stack overflow?
Show answerAllocating more memory on the stack than its fixed size allows, often due to excessive recursion or large local arrays.
Where are local variables typically stored?
Show answerOn the stack, where they are automatically deallocated when their function exits.
What is the heap in memory management?
Show answerA large, dynamically-allocated region of memory used for objects whose size or lifetime cannot be determined at compile time.
Why is heap allocation slower than stack allocation?
Show answerThe heap requires dynamic memory management via algorithms like searching for free blocks, whereas the stack uses simple pointer arithmetic.
What is external fragmentation on the heap?
Show answerGaps of unused memory scattered throughout the heap between allocated blocks, making it hard to find contiguous free space.
Can objects on the heap be automatically freed without garbage collection?
Show answerNo, they persist until explicitly deallocated or collected.
What is internal fragmentation?
Show answerWasted memory within an allocated block due to the block being larger than the object it holds.
How does reference counting work?
Show answerEach object maintains a count of how many pointers reference it; when the count reaches zero, the object is freed.
When is an object freed in reference counting?
Show answerImmediately when its reference count drops to zero.
What is the circular reference problem in reference counting?
Show answerTwo or more objects that reference each other form a cycle where counts never reach zero, causing a memory leak even with reference counting.
What is the overhead of reference counting?
Show answerEvery pointer assignment requires incrementing or decrementing a count, consuming CPU time and potentially adding cache misses.
Must reference count operations be atomic in concurrent systems?
Show answerYes, to prevent race conditions from multiple threads accessing the same count simultaneously.

20 more cards in the app

Study this set free