![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 8
Rep Power: 0
![]() |
memory leak question
I'm building a linked list class and have a question about one of my memeber functions. This is what i have now:
//Removes the last item from a linked list
void linked_list::pop_tail()
{
ll_item *cursor;
cursor = head;
while (true)
{
if(cursor->next_item->next_item == NULL)
{
delete cursor->next_item;
cursor->next_item = NULL;
break;
}
cursor = cursor->next_item;
}
size--;
}It works fine but I'm curious about the necessity of the first statement inside the if clause. Do I really need to delete the memory contents of next_item if I'm setting it to null, i.e. can I get away with just setting it to null without a memory leak? |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|