HomeSubjectsUniversityBlogAbout

Memory Management Concepts

Topic in Programming

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

Memory management is the way a program and its runtime allocate, use and release memory for data during execution, whether manually or automatically. Questions compare stack and heap allocation, pass-by-value and pass-by-reference, and shallow versus deep copying. For manual management, expect malloc and free, new and delete, pointers and pointer arithmetic, dangling pointers, double frees and memory leaks, plus C++ smart pointers and RAII. Garbage collection topics include reference counting and its cycle problem, mark-and-sweep, and generational collectors built on the generational hypothesis. Broader questions touch on virtual memory, arena allocation and why memory-safe languages prevent entire classes of bugs.

Below are 30 practice questions from a pool of 210 Memory Management Concepts MCQs, one of 16 topics in Programming. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

Memory Management ConceptsEasy

Q1. What is RAM?

  1. A.Random Access Memory, volatile memory for programs✓ Correct
  2. B.A programming language for system-level development
  3. C.A type of hard drive for persistent data storage
  4. D.Read-Access Module for hardware communication

Explanation

RAM (Random Access Memory) is volatile memory that stores data and program code currently being used by the CPU.

Report an error in this question

Memory Management ConceptsEasy

Q2. What is the stack in memory?

  1. A.A memory region storing locals and call info in LIFO✓ Correct
  2. B.The hard drive used for persistent data storage
  3. C.A data structure only with no memory role
  4. D.A type of processor cache for fast data access

Explanation

The stack stores local variables, function parameters, and return addresses in a Last-In, First-Out manner.

Report an error in this question

Memory Management ConceptsEasy

Q3. What is a memory leak?

  1. A.A security vulnerability in network protocols
  2. B.A hardware failure in the memory modules
  3. C.A type of buffer overflow in array operations
  4. D.Allocated memory no longer used but not freed✓ Correct

Explanation

A memory leak occurs when a program allocates memory but fails to release it after use.

Report an error in this question

Memory Management ConceptsEasy

Q4. What is the heap in memory?

  1. A.Read-only memory that cannot be written to
  2. B.Identical to the stack memory region exactly
  3. C.A sorted data structure for priority access
  4. D.A memory region for dynamic memory allocation✓ Correct

Explanation

The heap is a memory region where dynamically allocated objects reside; memory is allocated and freed in any order.

Report an error in this question

Memory Management ConceptsEasy

Q5. What is a variable's lifetime?

  1. A.The duration the variable exists in memory✓ Correct
  2. B.Its declared data type in the program
  3. C.Its identifier name in the source program
  4. D.Its accessibility scope in the source code

Explanation

A variable's lifetime is the period from when memory is allocated for it until that memory is deallocated.

Report an error in this question

Memory Management ConceptsEasy

Q6. What is the difference between stack and heap allocation?

  1. A.Stack is automatic and fast with limited size; heap is larger but slower✓ Correct
  2. B.Heap allocation is always faster than stack allocation in all scenarios
  3. C.There is no meaningful difference between the two allocation methods
  4. D.Stack memory is unlimited while heap memory has a very strict size cap

Explanation

Stack allocation is automatic, fast, and limited; heap allocation is dynamic, larger, but slower and requires explicit deallocation or garbage collection.

Report an error in this question

Memory Management ConceptsEasy

Q7. What is garbage collection?

  1. A.A sorting algorithm for ordering data values
  2. B.Deleting files from the disk storage system
  3. C.Running disk cleanup utilities on the system
  4. D.Automatic reclamation of unused object memory✓ Correct

Explanation

Garbage collection automatically identifies and frees memory that is no longer referenced by the program.

Report an error in this question

Memory Management ConceptsEasy

Q8. What does 'free()' do in C?

  1. A.Frees up disk space on the storage drive
  2. B.Deallocates previously allocated heap memory✓ Correct
  3. C.Resets a variable back to its default value
  4. D.Allocates new memory on the heap for use

Explanation

free() releases dynamically allocated memory back to the system.

Report an error in this question

Memory Management ConceptsMedium

Q9. What is the difference between malloc() and calloc() in C?

  1. A.They are exactly the same function with no differences
  2. B.malloc initializes all allocated memory bytes to zero
  3. C.malloc allocates uninitialized; calloc initializes to zero✓ Correct
  4. D.calloc is always faster than malloc in all scenarios

Explanation

malloc() allocates uninitialized memory; calloc() allocates memory for an array and initializes all bytes to zero.

Report an error in this question

Memory Management ConceptsMedium

Q10. What is a dangling pointer?

  1. A.A pointer referencing already freed memory✓ Correct
  2. B.A pointer to a valid live object in memory
  3. C.A pointer with a null value assigned to it
  4. D.A smart pointer that manages object lifetime

Explanation

A dangling pointer points to memory that has been freed, leading to undefined behavior if accessed.

Report an error in this question

Memory Management ConceptsEasy

Q11. What is a pointer?

  1. A.A composite data type definition
  2. B.A variable storing a memory address✓ Correct
  3. C.A reusable block of executable code
  4. D.A variable holding a computed value

Explanation

A pointer holds the memory address of another variable, enabling indirect access to data.

Report an error in this question

Memory Management ConceptsMedium

Q12. What is a buffer overflow?

  1. A.Slow memory access due to fragmentation issues
  2. B.Writing data beyond the allocated buffer boundary✓ Correct
  3. C.Running out of available system memory completely
  4. D.A type of memory leak from unreleased resources

Explanation

A buffer overflow occurs when data exceeds the buffer's allocated size, overwriting adjacent memory.

Report an error in this question

Memory Management ConceptsEasy

Q13. What is a null pointer?

  1. A.A pointer to the memory address zero
  2. B.A pointer that has been deleted already
  3. C.A pointer to the stack memory region
  4. D.A pointer to no valid memory location✓ Correct

Explanation

A null pointer holds a special value indicating it does not point to any valid object or memory location.

Report an error in this question

Memory Management ConceptsMedium

Q14. What is reference counting as a garbage collection strategy?

  1. A.Counting variables in the current scope of code
  2. B.Tracking reference count and freeing at zero count✓ Correct
  3. C.A manual memory management technique using counters
  4. D.Counting the total number of memory blocks allocated

Explanation

Reference counting maintains a count of references to each object; when the count drops to zero, the object is immediately deallocated.

Report an error in this question

Memory Management ConceptsMedium

Q15. What is virtual memory?

  1. A.Shared memory accessible by multiple processes at once
  2. B.Cloud storage accessible over the internet network
  3. C.Using disk space to extend memory beyond physical RAM✓ Correct
  4. D.Encrypted memory for storing sensitive data securely

Explanation

Virtual memory maps memory addresses to physical RAM or disk, allowing programs to use more memory than physically available.

Report an error in this question

Memory Management ConceptsMedium

Q16. What is memory fragmentation?

  1. A.Memory that has been encrypted for data security
  2. B.Memory that has been compressed to save space
  3. C.Corrupted memory caused by hardware failures in RAM
  4. D.Free memory broken into small non-contiguous blocks✓ Correct

Explanation

Memory fragmentation occurs when free memory is scattered in small blocks, potentially preventing large contiguous allocations.

Report an error in this question

Memory Management ConceptsMedium

Q17. What is the difference between deep copy and shallow copy regarding memory?

  1. A.Deep copy allocates new memory for nested objects; shallow copies refs✓ Correct
  2. B.Shallow copy always uses more memory than deep copy for same structure
  3. C.There is no difference in memory usage between the two copy methods
  4. D.Deep copy uses less memory than shallow copy by sharing object refs

Explanation

Shallow copy copies references, sharing memory for nested objects. Deep copy allocates new memory and recursively duplicates all nested objects.

Report an error in this question

Memory Management ConceptsMedium

Q18. What are smart pointers in C++?

  1. A.Regular raw pointers with no extra features at all
  2. B.Objects that wrap pointers and manage memory automatically✓ Correct
  3. C.Pointers that point to function addresses in the program
  4. D.Pointers that find data faster through optimized algorithms

Explanation

Smart pointers (unique_ptr, shared_ptr, weak_ptr) automatically manage the lifetime of dynamically allocated objects, preventing memory leaks.

Report an error in this question

Memory Management ConceptsMedium

Q19. What is a memory pool?

  1. A.A pre-allocated block for smaller allocations reducing fragmentation✓ Correct
  2. B.A collection of physical memory hardware modules
  3. C.A memory leak caused by unreleased dynamically allocated resources
  4. D.A type of processor cache that stores frequently accessed data values

Explanation

A memory pool pre-allocates a large block and serves smaller allocation requests from it, reducing fragmentation and overhead.

Report an error in this question

Memory Management ConceptsMedium

Q20. What is the RAII pattern?

  1. A.A design pattern for building user interfaces
  2. B.A type of garbage collection used in managed languages
  3. C.Tying resource lifetime to object lifetime via destructors✓ Correct
  4. D.A memory allocation algorithm for dynamic memory pools

Explanation

RAII ties resource management to object lifetime: resources are acquired in constructors and released in destructors.

Report an error in this question

Memory Management ConceptsHard

Q21. What is the mark-and-sweep garbage collection algorithm?

  1. A.Marking files for deletion from the disk system
  2. B.A disk cleanup algorithm for removing temporary files
  3. C.A memory allocation method for new object creation
  4. D.A GC that marks reachable objects then frees unmarked✓ Correct

Explanation

Mark-and-sweep traverses from root references to mark reachable objects, then frees all unmarked objects.

Report an error in this question

Memory Management ConceptsHard

Q22. What is escape analysis in JVM?

  1. A.Compiler analysis determining if object references escape scope✓ Correct
  2. B.Network traffic analysis for monitoring data flow patterns
  3. C.Analyzing program exit codes and termination conditions
  4. D.Exception analysis for tracking error propagation in code

Explanation

Escape analysis determines if an object is only used within a method; if so, it can be allocated on the stack instead of the heap.

Report an error in this question

Memory Management ConceptsHard

Q23. What is a slab allocator?

  1. A.A garbage collector that runs periodically in background
  2. B.A simple wrapper around the standard malloc function call
  3. C.A disk allocator that manages file system block assignments
  4. D.A mechanism pre-allocating and caching object-sized blocks✓ Correct

Explanation

A slab allocator pre-allocates memory in slabs of object-sized chunks, reducing fragmentation for frequently created/destroyed objects.

Report an error in this question

Memory Management ConceptsHard

Q24. What is a generational garbage collector?

  1. A.A manual memory manager without automatic collection
  2. B.A garbage collector for old legacy programs only
  3. C.A GC dividing objects by age, collecting young often✓ Correct
  4. D.A reference counting garbage collection implementation

Explanation

Generational GC exploits the observation that most objects die young, collecting the young generation more frequently for efficiency.

Report an error in this question

Memory Management ConceptsHard

Q25. What is memory-mapped files and how do they work?

  1. A.Files mapped into virtual address space for memory I/O✓ Correct
  2. B.Files that have been encrypted for secure data storage
  3. C.Files that are stored only in volatile RAM memory
  4. D.Files that have been compressed to save disk space used

Explanation

Memory-mapped files map file contents into the process's virtual address space, enabling efficient I/O by reading/writing memory addresses.

Report an error in this question

Memory Management ConceptsHard

Q26. What is the difference between unique_ptr, shared_ptr, and weak_ptr in C++?

  1. A.unique_ptr is exclusive; shared_ptr shares; weak_ptr observes only✓ Correct
  2. B.They are all the same smart pointer type with no differences
  3. C.shared_ptr cannot be copied or assigned to another shared_ptr var
  4. D.unique_ptr is always slower than the other two smart pointer types

Explanation

unique_ptr has sole ownership. shared_ptr allows multiple owners via reference counting. weak_ptr observes without preventing deallocation.

Report an error in this question

Memory Management ConceptsHard

Q27. What is the ABA problem in lock-free memory management?

  1. A.When a location changes A to B to A, making CAS incorrectly succeed✓ Correct
  2. B.A problem related to the alphabet ordering of values
  3. C.A variant of buffer overflow caused by writing past array boundaries
  4. D.A type of memory leak caused by circular reference chains in objects

Explanation

The ABA problem occurs when a value changes A->B->A; CAS sees the original value and succeeds incorrectly.

Report an error in this question

Memory Management ConceptsHard

Q28. What is a write barrier in garbage collection?

  1. A.A mechanism intercepting pointer writes for GC invariants✓ Correct
  2. B.A memory protection scheme against buffer overflows
  3. C.A disk write cache for improving I/O performance
  4. D.A network firewall for filtering traffic

Explanation

A write barrier intercepts pointer writes to maintain GC data structures, such as recording cross-generation references.

Report an error in this question

Memory Management ConceptsHard

Q29. What is address space layout randomization (ASLR)?

  1. A.Randomizing process memory addresses to prevent attacks✓ Correct
  2. B.A memory allocation strategy for dynamic array growth
  3. C.An addressing mode for accessing hardware registers
  4. D.A sorting algorithm for ordering memory addresses

Explanation

ASLR randomizes positions of stack, heap, and libraries in a process's address space, making it harder for attackers to predict memory locations.

Report an error in this question

Memory Management ConceptsHard

Q30. What is Copy-on-Write (COW)?

  1. A.Sharing memory until a write triggers actual copying✓ Correct
  2. B.Copying files manually between directories on disk
  3. C.A garbage collection algorithm for reclaiming memory
  4. D.An error handling technique for runtime exceptions

Explanation

COW defers copying memory until a write occurs; multiple references share the same memory, and a copy is made only when modification happens.

Report an error in this question

Ready to test yourself on Memory Management Concepts?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start Memory Management Concepts Quiz