Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:59:18+00:00 2026-06-14T13:59:18+00:00

So I have a linked list getting created correctly, linked properly but when I

  • 0

So I have a linked list getting created correctly, linked properly but when I try to de-allocate memory I can’t seem to delete any node, the list still exists.
Code for my list deconstructor:

void LL_User::free_memory() {
    // TODO
    LL_User_Node *currentNode;
    currentNode = head;
    while(currentNode) {
        LL_User_Node *temp = currentNode;
        currentNode = currentNode->next;
        delete temp;
    }
    //cout << "LL_User::free_memory() is not implemented yet.\n";
}

LL_User::~LL_User() {
    if(head == NULL) {
        return;
    }
    free_memory();
}

And my user class has this for the vars and deconstructor:

User::User() {
    username = "";
    password = "";
    first_name = "";
    last_name = "";
    profile_pic_filename = "";
    birth_year = 0;
    birth_month = 0;
    birth_day = 0;
}

User::~User() {
    //Nothing placed in body because strings and ints are dealt with by OS?
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:59:19+00:00Added an answer on June 14, 2026 at 1:59 pm

    The code as written now only has one serious flaw; you delete the list chained to head, but never set head to NULL. Anyone touching it from this point on is hitting undefined behavior through a garbage pointer.

    Set head to NULL if you’re wiping the list like this. Alternatively, since you know head should be NULL after this is done anyway, forego using currentNode at all. Simply use head itself as the pointer that is walking the list. Think about that for awhile and it will come to you.

    Also, as-written the check for (head == NULL) is not needed in your destructor. It is already checked in your free_memory() function, as it should be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a Linked List into Java. I have created everything, but I
I have to implement a one linked list but it should put object in
I have following piece of code for reversing the linked list. I am getting
I have a simple doubly linked list example that I'm working on, but for
I wrote a quick generic linked list, simple stuff. But I have a bug
I have a Linked List and I want to implement a function: Random_Shuffle_List (struct
I have a linked list, which stores groups of settings for my application: typedef
Say you have a linked list structure in Java. It's made up of Nodes:
I have a singly-linked list containing 1 value in each element. struct listElement {
I have a singly linked list with node and list structs defined as: typedef

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.