Prepare for the 241 Computer Science Certification Exam with comprehensive flashcards and multiple choice questions. Enhance knowledge with explanations and hints to excel in your test journey!

Multiple Choice

Which describes mark-and-sweep garbage collection?

Mark-and-sweep is a form of automatic memory management. In the mark phase, the collector traces from root references (such as variables on the stack and global references) and marks every object that can be reached as live. In the sweep phase, it goes through the heap and reclaims the memory occupied by objects that weren’t marked, effectively freeing garbage. This two-step process ensures memory is reclaimed without programmer intervention and can handle cycles that simple reference counting might miss. It’s different from creating a new space and copying live objects there, and it doesn’t require manual deallocation.

Mark-and-sweep is a form of automatic memory management. In the mark phase, the collector traces from root references (such as variables on the stack and global references) and marks every object that can be reached as live. In the sweep phase, it goes through the heap and reclaims the memory occupied by objects that weren’t marked, effectively freeing garbage. This two-step process ensures memory is reclaimed without programmer intervention and can handle cycles that simple reference counting might miss. It’s different from creating a new space and copying live objects there, and it doesn’t require manual deallocation.