"new", "delete", "memory leak"

Hi!

I have read several posts in the internet, and what I understand is as follows. Please correct me if I am wrong / missing something.

1. Whatever memory we allocate dynamically using "new" has to be "deleted" manually before the program / function ends. Otherwise, it leads to a memory leak.
2. What happens if a memory leak does occur?
- the CPU memory is allocated unnecessarily to an unproductive task and becomes unavailable for other processes.
- the above memory is finally freed only on system shutdown. is it?
1. Yes
2.
- Computer memory, not CPU. Also problems with swapping can arise.
- It is freed when program finishes executing: either when it finished nomally, or if OS will forsibly close it becuse of memory issues.
thanks for your response MiNiPaa.

By "program finishes executing" I assume you mean that if I have allocated a new memory space in a "function", then that memory space remains allocated till the entire program finishes executing. right?

Now let's say my program is just about writing to a txt file. It exits / returns normally after the operation.

Do I need to worry about memory leaks of about 10-15 GUI objects that I created?
that memory space remains allocated till the entire program finishes executing. right?
Yes

Do I need to worry about memory leaks of about 10-15 GUI objects that I created?
It is better to worry about each memory leak. Even if they are not a problem now, the can become one later when your program will grow more complex and harder to debug.
Also it is good to form habit of correct memory management (Which in most cases boils down to "do not use manual memory allocation") and use of patterns like RAII.
ok.. will need to read up more about RAII. thank you!
Topic archived. No new replies allowed.