0
0
C++programming~5 mins

Memory leak concept in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a memory leak in C++?
A memory leak happens when a program allocates memory but never frees it, causing the memory to stay used and unavailable for other parts of the program or system.
Click to reveal answer
beginner
Why are memory leaks a problem?
Memory leaks reduce the available memory over time, which can slow down or crash programs because they run out of memory to use.
Click to reveal answer
intermediate
How do you prevent memory leaks in C++?
You prevent memory leaks by always freeing memory you allocate with 'delete' or 'delete[]' and by using smart pointers that automatically manage memory.
Click to reveal answer
beginner
What is an example of a memory leak in C++?
If you use 'new' to create an object but never use 'delete' to free it, the memory stays allocated and causes a leak.
Click to reveal answer
intermediate
What tools can help detect memory leaks in C++?
Tools like Valgrind or AddressSanitizer can find memory leaks by tracking allocated memory and checking if it is properly freed.
Click to reveal answer
What causes a memory leak in C++?
AWriting to a file
BUsing variables inside functions
CAllocating memory with 'new' and not freeing it with 'delete'
DDeclaring too many variables
Which C++ feature helps automatically manage memory and avoid leaks?
AGlobal variables
BSmart pointers
CMacros
DInline functions
What happens if a program has a memory leak?
AIt runs faster
BIt reduces CPU usage
CIt frees memory automatically
DIt uses more memory over time and may crash
Which tool can help find memory leaks in C++ programs?
AValgrind
BGCC compiler
CGit
DMakefile
What must you do after using 'new' in C++ to avoid leaks?
AUse 'delete' to free the memory
BUse 'malloc' instead
CDo nothing, memory frees automatically
DUse 'cout' to print the memory
Explain what a memory leak is and why it is important to avoid it in C++ programs.
Think about what happens when memory is allocated but never freed.
You got /3 concepts.
    Describe how smart pointers help prevent memory leaks in C++.
    Smart pointers act like helpers that clean up memory for you.
    You got /3 concepts.