In many cases we declare a pointer dynamically in a function, and sometimes we don't want to free that memory at the return of the function, because we need that memory later.
We can return that dynamic pointer and later free it. I found some way to track that memory. Is that a good thing:
#include <iostream>
int foo()
{
int* pInt = new int(77);
int x = (int)pInt;
std::cout << std::hex << x << std::endl; // 3831d8
return x;
}
int main()
{
int* pLostMem = (int*)foo();
std::cout << pLostMem << std::endl; // 003831D8
std::cout << std::dec << *pLostMem << std::endl; // 77
if(pLostMem)
{
delete pLostMem;
pLostMem = NULL;
}
std::cout << std::endl;
return 0;
}