Click to See Complete Forum and Search --> : Memory Management


utsavgupta
April 12th, 2008, 06:05 AM
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

Chipmunk Baby
April 12th, 2008, 10:34 AM
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.

exterminator
April 12th, 2008, 11:54 PM
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.