After a sequence of new/delete on structs, I seem to have memory loss
<p>I have a linked list of structs each of which contains an integer and a pointer to the next struct. Before populating this struct by a sequence of new commands, I note down the memory used (say Mem_1) by this program in Windows Task Manager under "Mem Usage". The actual linked list creation occurs next. (See void populate(int i) function below). Then, I use a sequence of deletes to try and delete this linked list and hopefully reclaim the memory. After the deletes, I check the memory again in the Task Manager. This time the amount of memory used is, say, Mem_2. I notice that Mem_2 > Mem_1. Should not Mem_2 = Mem_1? Or is there some dangling pointer I am not properly taking care of. </p>

<p>Thanks for your help in advance...(The code is a console application/VS2008/Windows XP platform)</p>

<pre><code>struct item_s{
int value;
item_s* next;
};

struct item_s* item = NULL;
struct item_s* last_item = NULL;
struct item_s* last_accessed = NULL;

void populate(int i){
     if(item == NULL){
    item = new item_s;
    item-&gt;value = i;
    item-&gt;next = NULL;
    last_item = item;
}
else{
    last_item-&gt;next = new item_s;
    last_item-&gt;next-&gt;value = i;
    last_item-&gt;next-&gt;next = NULL;
    last_item = last_item-&gt;next;
}
}

void main(){
for(i = 1; i &lt;= 10000; i++){
    populate(i);
}
last_item = item;
last_accessed = last_item-&gt;next;
while(last_item!=NULL){
    delete last_item;
    last_item = last_accessed;
    if(last_item!=NULL){
        last_accessed = last_item-&gt;next;
    }
}
}
</code></pre>
