help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory Leak??


From: nandakiran
Subject: Re: Memory Leak??
Date: Fri, 24 Aug 2007 22:30:55 -0000
User-agent: G2/1.0

when i run  ksysguard. it shows that my memory is not de-allocated,
and around 40mb of memory
is still being allocated to my program (after reaching printf("ok")).
whereas, In the first case, after the end of delete's , only 4 mb of
memory
is allocated to my program.

On Aug 24, 4:30 pm, red floyd <no.s...@here.dude> wrote:
> nandaki...@gmail.com wrote:
> > I am using Mandriva Linux (2.6.17-14) with gnu g++ version 4.1.2. The
> > source code used to test is given below.
> > When i am run the program, it is properly freeing up the allocated
> > memory. When also including the
> > lines that are commented in the code, the "delete" is not freeing up
> > the memory used. I do not have
> > the problem when compiling under cygwin.  What can be done to fix
> > this?
>
> > Source Code:
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <string.h>
> >    struct node {
> >            char *value;
> >            char temp[5000];
> >            node *right;
> >    } *head;
>
> > int main() {
> >    int i;
> >    node* tmp;
> >    tmp=NULL;
> >    for (i=0;i<10000;i++) {
> >            head=new node;
> >            // head->value = NULL;
> >            // head->value = new char;
> >            // *(head->value)='C';
> >            head->right=tmp;
> >            tmp=head;
> >    }
> >    do {
> >            tmp=head->right;
> >            // delete (head->value);
> >            // head->value=NULL;
> >            delete head;
> >            head=tmp;
> >    } while (head!=NULL);
> >    printf("OK!\n");
> >    for (;;);
> > }
>
> What makes you think you have a memory leak?- Hide quoted text -
>
> - Show quoted text -




reply via email to

[Prev in Thread] Current Thread [Next in Thread]