It's when you allocate memory but don't release it.
1 2 3 4 5 6 7 8 9
#include <iostream>
int main( int argc, char* argv[] )
{
int *myInt= newint(5); // Memory allocated here
std::cout << "myInt is " << *myInt << std::endl;
return 0;
}
What should be done...
1 2 3 4 5 6 7 8 9 10
#include <iostream>
int main( int argc, char* argv[] )
{
int *myInt= newint(5); // Memory allocated here
std::cout << "myInt is " << *myInt << std::endl;
delete myInt; // Memory released here
return 0;
}
If you're constantly using the stack then worrying about memory leaks is pointless, though. I thought an example of freeing up allocated heap memory was the best way to go.