Quickie Linked List Deallocation question.

This is a discussion on Quickie Linked List Deallocation question. within the C# Programming forums, part of the General Programming Boards category; Okie, just started using C# a few days ago and it seems relatively easy although I wanted to get one ...

  1. #1
    Registered User Kurisu's Avatar
    Join Date
    Feb 2006
    Posts
    62

    Quickie Linked List Deallocation question.

    Okie, just started using C# a few days ago and it seems relatively easy although I wanted to get one thing clarified so I don't run into problems down the road.

    A linked list in C# unlike C++ or C does not require manual freeing of memory?

    That is, C#'s garbage collector will automatically handle freeing of a linked list thus requiring no destructor?

    Allocation of memory never requires me to worry about freeing memory? Ever?

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    That's right. .Net's garbage collection is pretty good; when you can no longer access a piece of memory, it is marked for deletion. You don't even have to worry about circular references. The only time you have to worry about freeing resources is when you have unmanaged resources. Then you should implement IDisposable using the IDisposable pattern mentioned on MSDN.

    Just wondering, are you implementing a linked list class? If so, why not just use the generic LinkedList class?
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User Kurisu's Avatar
    Join Date
    Feb 2006
    Posts
    62
    Ah, sounds kinda sweet.

    Quote Originally Posted by pianorain
    Just wondering, are you implementing a linked list class? If so, why not just use the generic LinkedList class?
    I've got a bad habit of creating my own linked structures for my personalized situation instead of using the provided one since I was forced in school to write my own for learning purposes. Don't know why.. guess its a habit I should break.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    Quote Originally Posted by Kurisu
    Ah, sounds kinda sweet.



    I've got a bad habit of creating my own linked structures for my personalized situation instead of using the provided one since I was forced in school to write my own for learning purposes. Don't know why.. guess its a habit I should break.
    And I applaud you for that. Many people recommend learners use a feature already provided in the language but, I think that is a bad idea most of the time. The more things you do on your own, the more you learn (reinventing the wheel ) . It's that simple. After you learn, then I agree that you should use what the language provides over your alternative.

  5. #5
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Aye, I agree that it's useful as a learning construct. However, it should usually be abandoned in other code. The data types provided by the library are implemented so that they work together and rigorously tested. This makes it a pretty dependable library to work with.

    As another learning exercise, you might try implementing all of the interfaces from LinkedList<T> on your custom linked list class. If your class is generic, that'd be ICollection<T>, ICollection, ISerializable, and IDeserializationCallback. If your class isn't generic, you can leave off ICollection<T>. This is useful because it gives you the experience of implementing interfaces (which isn't always as straightforward as it seems), and you can now use your custom linked list class where ever something was expecting one of those interfaces.

    If you really want to exercise those coding skills, write a generic binary tree data type for .Net, implementing IDictionary<Tkey,Tvalue>, ISerializable, and IDeserializationCallback. I was surprised that the standard assembilies didn't come with one.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list question
    By brb9412 in forum C Programming
    Replies: 16
    Last Post: 01-04-2009, 03:05 PM
  2. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  3. Replies: 5
    Last Post: 11-04-2006, 05:39 PM
  4. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 05:40 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21