473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

link list -is this enough?

Hi,
I have a single link list. at the end of the program or in a
loop i want to destroy this link list.
so is it enough to free the pointer to this link list
or do i have to traverse whole link list until last node where next
field is null and free each node.
please suggest.
thanks
lee
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Nov 14 '05 #1
2 1373
Yang Lee wrote:
Hi,
I have a single link list. at the end of the program or in a
loop i want to destroy this link list.
so is it enough to free the pointer to this link list
or do i have to traverse whole link list until last node where next
field is null and free each node.
please suggest.


Lee...

If each list element was allocated using malloc() or calloc(),
then each element will need to be individually free()'d.

If storage for the entire list was allocated with a single
malloc() or calloc() call, then you'll need to use just one
free() call.

If the storage for the list wasn't allocated using malloc() or
calloc(), then you'd best not free() it.

--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.

Nov 14 '05 #2
> so is it enough to free the pointer to this link list
or do i have to traverse whole link list until last node where next
field is null and free each node.


If you free the pointer to the linked list your program will experience
a memory leak, so you should traverse the list and at each node record
the next pointer and then free the current node. Repeat this for all
nodes in the list.

Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Murat Tasan | last post by:
i'm having trouble with some links using javadoc... basically, here is the example: {@link List}. {@link List#set(int, Object) List.set}. i'll run javadoc, but only the first link shows up....
26
by: Harrie | last post by:
Hi, After Brian mentioned the use for <link rel=..> for navigational purposes in another thread, I've been looking into it and found that HTML 3.2 has two other recognized link types than HTML...
1
by: Kane | last post by:
When you create node 1 you allocate memory and link it Again when you create node 2 you would allocate memory for that node in a different section of the code. Is there more efficient way where I...
8
by: sudhirlko2001 | last post by:
How to swap two nodes of doubly Linklist
14
by: Steve McLellan | last post by:
Hi, Sorry to repost, but this is becoming aggravating, and causing me a lot of wasted time. I've got a reasonably large mixed C++ project, and after a number of builds (but not a constant...
4
by: emanshu, Munish Nayyar | last post by:
Hi all, i am looking for different solutions for the fow:- problems please let me know if anyone have any idea. problem 1:- we have link list ( singly link list ), in which some node( say X...
5
by: kjmatthews | last post by:
I am designing a site but only have access to a Mac, equipped with Virtual PC. On IE6 is appears that, on some pages of this site, the navigation does not appear. I have put up a test case:...
9
by: incredible | last post by:
how to sort link list of string
2
by: pauld | last post by:
Hello- I'm sure this has been asked and answered before since it is a common technique, but I can't seem to get the search terms needed to get me an answer, so I thought I would post here. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.