Say I have the following program for demonstration purposes only:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *my_memory = malloc(50000);
int *my_int = malloc(sizeof(int));
//Do other things but never free my_memory or my_int
return 0;
}
According to Wikipedia:
In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations1 in such a way that memory which is no longer needed is not released. A memory leak may also happen when an object is stored in memory but cannot be accessed by the running code.[2]
Sentence #1 implies that a memory leak can be unneeded, unfreed memory. However, many, many programmers I've worked with have stated that "there is no memory leak because the OS frees the memory." These programmers believe that memory leaks only occur if there is no longer a reference point or handle to some allocation, thus making it no longer accessible and no longer able to be freed.
As far as I know, it is true that the OS does free the memory, in regards to modern macOS, Windows, and Linux.
I've used AddressSanitizer, Dr. Memory, and Valgrind; they flag this type of program as having "memory leaks."
So my question is, is an example such as the above, where memory is allocated and not freed before program termination, a memory leak or not?