MHB Separating a List: What to Do After Deallocating?

  • Thread starter Thread starter mathmari
  • Start date Start date
  • Tags Tags
    List
Click For Summary
When deleting a list from an array of linked-lists, it is essential to deallocate all nodes of the list to ensure proper memory management. After deallocating the nodes, the corresponding entry in the array should be set to NULL to indicate that there is no longer a list attached to that position. If the array itself is not dynamically allocated, no further action is required regarding the array. This process ensures a clean removal of the list and helps prevent memory leaks.
mathmari
Gold Member
MHB
Messages
4,984
Reaction score
7
Hey! :o

When I have to delete a list from an array of linked-lists, do I have to delete all the nodes of the list? Or do I have to do also something at the array??

There is a list, I have to separate this list into two others and delete the initial list from the array.

I used a function to deallocate the list. What else should I do?? (Wondering)
 
Technology news on Phys.org
mathmari said:
Hey! :o

When I have to delete a list from an array of linked-lists, do I have to delete all the nodes of the list? Or do I have to do also something at the array??

There is a list, I have to separate this list into two others and delete the initial list from the array.

I used a function to deallocate the list. What else should I do?? (Wondering)

Hi! (Blush)

To destroy everything cleanly, we should iterate over the array, and iterate over each list in the array, deallocating the nodes as we go. Then the corresponding entry in the array should be set to NULL to indicate there is no list attached to it anymore. (Nerd)

There is nothing else to do with the array (assuming it was not dynamically allocated).
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
998
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K
Replies
15
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
Replies
9
Views
3K