CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2007
    Posts
    3

    Exclamation Memory Management

    Hi,

    I wanted to know how can I free the memory when the program exits. I wrote a linked list program using the following structure:

    struct node
    {
    node *prev;
    char c;
    node *next;
    };

    When i exit the program and then again run it, the values which are displayed are the values which were entered in the previous run.

    I'm using Borland C++.

    Cheers,
    Utsav

  2. #2
    Join Date
    Dec 2007
    Posts
    50

    Re: Memory Management

    I don't know how such an explanation along with a struct helps people understand the real problem you come across. Clearification would bring back more help.

  3. #3
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: Memory Management

    There is, probably, something wrong with your linked list implementation. Also, it depends on what you mean by "exit the program". Is it in the context of your application or process of your application.

    One more thing to look at could be that you are using uninitialized pointers somewhere that you did not probably set to a valid object.

    It could also be hardcoded values or being read from file or some other stream which has got consistent persistent data and that is what you always get.

    Just wonder, how can you get the program to read the same values as the last run? The program isn't magic. It does what you told it to do. If you don't post you relevant code, no one can help. Use [CODE] tags as well.

    Also, just might be a better idea to use std::list<T>/std::list<char> which is a doubly linked list implementation inside the standard library that comes with your compiler. And if you are thinking this is just because of memory leaks/not freeing memory etc, I think that is the least of your worries.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured