Is this considered a memory leak?

General rule: only objects allocated in free storage can cause a memory leak. But there are no objects created on the stack.

Here are my doubts

int main()
    {
      myclass x;

      ...

      throw;

      ...
    }

If the cast is not processed, it calls, completes (), which, in turn, causes interruption () and the application to crash. At this time, objects on the stack are not destroyed (the destructor is not called).

My understanding: "When the application terminates (either interrupted or by a normal exit), it frees up all the memory allocated for the application." Therefore, this cannot be considered a memory leak.

Am I right?

+5
source share
7 answers

(, Unix/Windows/Mac OS X, DOS, ), , . .

, , , , , valgrind. .

- , . , ( malloc ). , , . , (, ), , . , , .

+5

edit: GMan, "throw;" , , . , .

, " ", , . , , " ".

+4

: . , . ( , 3.1 Linux-), , , .

+2

, - . , , , , .

+1

: " myclass , /?"

- , , , . ( ), . myclass . , .

myclass , dtor, , dtor , . Dtor , .

, , - myclass dtor, dtor . , , , dtors.

+1

OP,

, , terminate(), , , abort() . ( ).

, .

$15.3/9- " , terminate() ; () (15.5.1).

, , , .

+1

: " ( , ), , ". , .

?

- , - .

IOW, if the program does not end properly, aka crash, then it is too early to talk about memory leaks.

On the other hand, most of the memory analyzers I have worked with over the past decade will not cause any memory leak problems in this case - because they do not cause any alarms when the program crashes foggy. First you need to make the program not crash, and then debug the memory leak.

0
source

All Articles