Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!news-out.readnews.com!news-xxxfer.readnews.com!panix!not-for-mail From: Ruben Safir Newsgroups: comp.lang.c++ Subject: Interpeting valgrind Date: Sun, 22 May 2011 23:03:48 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 114 Message-ID: NNTP-Posting-Host: www2.mrbrklyn.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reader1.panix.com 1306105428 14072 96.57.23.82 (22 May 2011 23:03:48 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sun, 22 May 2011 23:03:48 +0000 (UTC) X-Blackjet: Blackjet is a Yankee Fan X-DRMisTHEFT: Use GNU Linux today X-From: A Dark Cloud X-LOCATION: Brooklyn NY - Forget abou' it! X-NYLXS: Really - yah think computers are supposed to be broken? User-Agent: Pan/0.133 (House of Butterflies) Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:5343 I'm looking at valg5rind output. Very interesting but I'm wondering about its output I see for example ==2109== ==2109== HEAP SUMMARY: ==2109== in use at exit: 249,696 bytes in 32,929 blocks ==2109== total heap usage: 39,794 allocs, 6,865 frees, 329,680 bytes allocated ==2109== ==2109== 4 bytes in 1 blocks are still reachable in loss record 1 of 17 ==2109== at 0x4027400: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==2109== by 0x804B50D: chainlist::Node >*>::value(chainlist::List >*) (linklist.h:112) ==2109== by 0x804AC67: chainlist::Node >*>::Node(chainlist::List >*, chainlist::Node >*>*) (linklist.h:82) ==2109== by 0x8049938: chainlist::List >*>::insert(chainlist::List >*) (linklist.h:267) ==2109== by 0x8048D23: main (test_del2.cpp:84) ==2109== Looking at linklist.h:112, 82, 267 these are part of my class 80 template Node::Node(unk val, Node *item_to_link_to){ value(val); if(!item_to_link_to){ next_ = 0; } 112 template void Node::value(unk val){ value_ = new unk(val); } 267 template < class T > void List::insert ( T val ) { if(!front()){ std::cout << "val is here" << std::endl; Node * tmp = new Node(val); std::cout << "tmp is " << tmp << std::endl; front(tmp); endd(tmp); cursor(tmp); sizeup(); return; Now, as far as I know, i took care of all these leaks in the destructuror template List::~List(){ remove_all(); // std::cout << "Deleted All*************" << __LINE__ << std::endl; } void List::remove_all(){ // std::cout << "remove_all " << __LINE__ << std::endl; cursor() = front(); while(cursor() != endd()){ // std::cout << "remove_all the front line" << __LINE__ << std::endl; remove_front(); } // std::cout << "\n\nReached the End\n\n"; remove_front(); // std::cout << "\n\nDeleted Last Node\n\n"; } template void List::remove_front(){ //// std::cout << "Removing the Front " << front() << " End of List is "<< endd() << std::endl; if(front() == 0){ // std::cout << "Front is NULL " << front() << std::endl; return; } if(front() == endd()){ // // std::cout << "Front is End " << front() << std::endl; Node * tmp = front(); delete tmp; front(0); endd(0); cursor() = 0; sizedown(); return; } template Node::~Node(){ if(value_) delete value_; // std::cout << "Delete Node" << __LINE__ << std::endl; } Anything not being destroyed is in global scope and left destroyed internationally...or so i thought When the program ends, main stops and a whole cascade of deletes happen. I've seen that happen in this code and even had double deletes at one point. Am I not seeing something? Ruben