The storage used for pointers passed as arguments will be cleared. But the memory they point to will not be cleared.
So for example:
void foo(int *p) // p is a copy here { return; // The memory used to hold p is cleared up, // but not the memory used to hold *p } int main() { int *p = new int; foo(p); // A copy of p is passed to the function (but not a copy of *p) }
You often hear people talking about "on the heap" and "on the stack." * Local variables (e.g. arguments) are stored on the stack, which is automatically cleared. Data allocated using new (or malloc ) is stored on the heap, which is not automatically cleared.
* However, the C ++ standard does not talk about the "stack" and the "heap" (in fact, these are implementation-specific details). It uses the terminology "automatic storage" and "distributed storage" respectively. Sub> source share