Ace Your C++ Skills 2026 – Rock the ‘Thinking in C++’ Challenge!

Question: 1 / 565

What should always follow a successful call to new in C++ to prevent resource leaks?

A call to free()

A call to delete

After creating an object using the new keyword in C++, a call to the delete keyword is necessary to free up the memory allocated for that object. This is because using new dynamically allocates memory for an object and it is the responsibility of the programmer to manage and free up that memory when it is no longer needed. Options A, C, and D do not properly address the issue of memory management and could potentially lead to memory leaks. A call to free() is typically used in conjunction with malloc() in C, but is not needed in C++ when using new. A call to the destructor is automatically made when an object is deleted, but does not free up the allocated memory. And "memory cleaning" is a broad term that does not specify the proper way to free up memory in this context. Thus, the only correct and necessary step to prevent resource leaks after a successful call to new

Get further explanation with Examzify DeepDiveBeta

A call to the destructor

Memory cleaning

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy