In what scenario might a program have a memory leak due to an exception being thrown?
- When the destructor isn't called
- When using global variables
- When an exception is caught and rethrown
- When exception specifications are used
A common memory leak scenario is when an exception is thrown before the memory allocated dynamically (usually with new) is deallocated. If the exception prevents a destructor or a delete statement from being reached, the memory is never released, resulting in a memory leak.
Loading...
Related Quiz
- Can a friend function of a class access the private members of that class?
- The _______ keyword is used to explicitly instantiate a template.
- Consider a large-scale application where multiple threads often access shared objects concurrently. Which smart pointer can be used to ensure that an object is deleted only when the last pointer to it is out of scope, considering thread safety?
- The expression a×b can be represented as a _______ b in C++.
- Which of the following data types can store a non-integer number?