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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *