Suppose we have the following C++ code:
while(condition)
{
Node* temp = SomeNode->next;
//...
}
destructor()
{
//delete Nodes;
}
And here temp is a local pointer variable and CurrentNode is a public class property. The public nodes and relevent nodes get freed in the destructor. But what happens to all the local scoped pointer variables. A pointer data type consumes some memory, for example 4 bytes or more (depending on the memory space), just for the address. Here, The temp local variable is not initialized with 'new' and is just a pointer to some other nodes, based on this, Is temp local variable made on the stack or on the heap? Does this local variable get destructed automatically soon after exiting the block or is it dynamic memory and yet needs using of delete. I saw some codes somewhere that did not use delete to free up local pointers that were not made with new. And I want to make sure if he missed freeing up the variables or there is some other story about it that I do not know. Thanks.
CurrentNodein your question,CurrentNodeis not shown in your code sample.