0
0
Intro to Computingfundamentals~20 mins

Memory management basics in Intro to Computing - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Memory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Memory Allocation

Which of the following best describes dynamic memory allocation in a computer program?

AMemory is only used to store program instructions, not data.
BMemory is fixed and reserved before the program starts running and cannot change during execution.
CMemory is allocated during program execution as needed, and can be freed when no longer required.
DMemory allocation happens only when the computer is turned off.
Attempts:
2 left
💡 Hint

Think about when the program decides how much memory it needs while running.

trace
intermediate
2:00remaining
Tracing Memory Usage in a Program

Consider this simple program that creates and deletes objects. What is the total number of objects in memory after the program finishes?

Intro to Computing
objects = []
for i in range(3):
    obj = {'id': i}
    objects.append(obj)
objects.pop(1)
objects.append({'id': 3})
A1
B4
C2
D3
Attempts:
2 left
💡 Hint

Count how many objects are added and removed step by step.

identification
advanced
2:00remaining
Identifying Memory Leak Causes

Which of the following scenarios is most likely to cause a memory leak in a program?

AA program keeps references to unused objects, preventing the memory from being freed.
BA program runs without any loops.
CA program uses only static memory allocation.
DA program frees memory immediately after using it.
Attempts:
2 left
💡 Hint

Think about what happens if memory is not released properly.

Comparison
advanced
2:00remaining
Comparing Stack and Heap Memory

Which statement correctly compares stack and heap memory?

AHeap memory is faster and smaller than stack memory.
BStack memory is for static, short-lived data; heap memory is for dynamic, long-lived data allocated at runtime.
CStack memory is used for storing files; heap memory stores program instructions.
DHeap memory is automatically cleaned up; stack memory requires manual management.
Attempts:
2 left
💡 Hint

Think about where local variables and dynamically created objects are stored.

🔍 Analysis
expert
2:00remaining
Output of Memory Reference Counting

What is the output of this Python code that demonstrates reference counting?

Intro to Computing
import sys

x = [1, 2, 3]
y = x
z = y
print(sys.getrefcount(x))
A4
B3
C1
D0
Attempts:
2 left
💡 Hint

Remember that getrefcount includes the temporary reference as an argument.