Thread: Freeing memory question

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    55

    Freeing memory question

    So I'm dealing with some linked lists and I was wondering if I have to free every node in the list or will just freeing the head of the list do the trick?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You need to free() every node, assuming you allocated each node separately. For every allocation, there should be a corresponding free(), always.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about memory
    By simo_mon in forum C Programming
    Replies: 7
    Last Post: 03-20-2009, 08:02 AM
  2. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  3. Freeing memory
    By C_ntua in forum C Programming
    Replies: 17
    Last Post: 06-29-2008, 04:42 AM
  4. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM