Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Mar 26th, 2005, 2:49 PM   #1
xaosai
Newbie
 
xaosai's Avatar
 
Join Date: Mar 2005
Posts: 8
Rep Power: 0 xaosai is on a distinguished road
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?
xaosai is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC