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-10 22:16

becuase lol seeples

Name: Anonymous 2012-01-10 22:16

read SICP

Name: Anonymous 2012-01-10 22:17

I have.

Name: Anonymous 2012-01-10 22:40

How to make a linked list:

(list 'oh 'my 'god 'so 'difficult)

Name: Anonymous 2012-01-10 22:48

>>5

That's lisp, not C++. OP needs C++.

Also, make a dynamic array in lisp.

Name: Anonymous 2012-01-10 22:50

>>6
(vector 'oh 'my 'god 'so 'difficult)

Name: Anonymous 2012-01-10 23:06

>>6
No, my young novice. The OP needs Lisp.

Name: Anonymous 2012-01-10 23:23

memory fragmentation

Name: Lisp 2012-01-11 0:04

>>1
DKIYT, what is the maximum value of your size_t? it looks like you're allocating a bit more than 6 and a half gigs.

Name: Anonymous 2012-01-11 0:08

why does this post lead to you checking my doubles

Name: Anonymous 2012-01-11 0:32

Because you're using C++. C master race repoting in.

Name: Anonymous 2012-01-11 1:11

From first glance it looks like head is leaking.

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

Name: Anonymous 2012-01-11 4:07

your code isn't exception safe either, thanks to C++.

Name: Arrogant Lisper 2012-01-11 4:18

Silly SEPPLESfags.

Name: Anonymous 2012-01-11 4:50

>>14
List didn't get head, lol
He has the reference to everything from the tail right?
t->p=tail;tail->n=t;tail=t;
and initially head is tail in the constructor

Name: Anonymous 2012-01-11 5:17


linkedlist *L= new linkedlist();
delete L

problem?

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