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!border4.nntp.dca.giganews.com!border2.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: Re: Interpeting valgrind Date: Tue, 24 May 2011 02:48:38 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 131 Message-ID: References: <70a85274-88f9-4a18-b45c-50f05e91773c@l26g2000yqm.googlegroups.com> 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 1306205318 11169 96.57.23.82 (24 May 2011 02:48:38 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Tue, 24 May 2011 02:48:38 +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++:5388 On Tue, 24 May 2011 00:54:17 +0200, Kai-Uwe Bux wrote: > Ruben Safir wrote: > > [...] >> But look at this >> ==26349== 121,600 (1,600 direct, 120,000 indirect) bytes in 100 blocks >> are definitely lost in loss record 17 of 17 ==26349== at 0x4027400: >> operator new(unsigned int) (in >> /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==26349== by >> 0x8048E49: creating_int_list() (test_del2.cpp:105) ==26349== by >> 0x8048A89: main (test_del2.cpp:55) ==26349== >> >> >> >> Ok those lines are as follows - the call function designed to allocate >> a list of integers and return them (in this case to main >> std::cout << "CREATING LIST for ARRAY >> -------------------------------\n"; a[i] = creating_int_list(); >> >> >> chainlist::List * creating_int_list(){ >> // chainlist::List set = new chainlist::List; >> chainlist::List * set = new chainlist::List; int ran; >> for(int i = 0; i < 100; ++i){ >> ran=rand(); >> set->insert(ran % 100); >> } >> set->display(); >> return set; >> } >> >> >> If I chose to delete the returned List pointed to by set, it have to be >> done OUT of that function otherwise the function has no point >> >> So upon complaint i did just that >> >> >> for( i=0; i < 100; ++i){ >> delete a[i]; >> } >> return EXIT_SUCCESS; >> >> >> That had NO IMPACT on the report. > [...] > > Then, it looks as though the destructor of chainlist::List is not > releasing the resources properly. I looked upthread for that destructor. > It relies upon a method remove_front() which you posted as: > > 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; > } > > The code looks incomplete, so I cannot comment on the correctness. But > that is, where I would search. > > > Best, > > Kai-Uwe Bux here is the complete destructor template List::~List(){ remove_all(); // std::cout << "Deleted All*************" << __LINE__ << std::endl; } template< class T> 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< class T> 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 Node::~Node(){ if(value_) delete value_; // std::cout << "Delete Node" << __LINE__ << std::endl; }