Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why does this lead to a memory leak

Name: Anonymous 2012-01-10 22:14

#include <iostream>
using namespace std;
class node{
long long data[1000];
double moredate[100];
public:
    node *n; node *p;
    node(void){ n=p=0; };
    ~node(){};
};
class linkedlist{
node *head, *tail;
unsigned long long int size;
public:
    linkedlist(){
        head=tail=new node();
        size=1;
    }
    ~linkedlist(){
        node *t=head;
        node *tt=0;
        for(;size>0;size--){
            tt = t->n;
            delete t;
            t=tt;
        }
    }
    void makeL(){
        node *t;
        for(unsigned long long int i=0;i<100000; i++){
            size++;
            t=new node();
            t->p=tail;tail->n=t;tail=t;
        }
        return;
    }
};

int main(){
    while(1){
    linkedlist *L= new linkedlist();
    L->makeL();
    char x;
    cout<<"made";
    cin>>x;
    delete L;
    cout<<"deleted";
    cin>>x;
    }
    return 0;
}

I'm deleting all the dynamic data aren't I?

Name: Anonymous 2012-01-11 1:29

head never gets assigned to anything in makel - you lose the reference to your linked list you create
dont allow an object to be in a half constructed state dum dum

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List