bug-commoncpp
[Top][All Lists]
Advanced

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

Thread doesn't release it's memory after execution. How to make it relea


From: Diogo Costa
Subject: Thread doesn't release it's memory after execution. How to make it release?
Date: Wed, 25 Aug 2004 17:28:41 -0300
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030313

Hi,

I am writing a c++ program using the GNU Common C++ Library. I am not been able to release the memory a thread has taken after it was executed. How could I do it? My program just keep o getting more and more memmory.

For example, the follow program should release some memory after the father and child threads end, but it doesn't. What is wrong?

#include <cc++/thread.h>
#include <cstdio>
#include <cstring>
#include <iostream>

#ifdef  CCXX_NAMESPACES
using namespace std;
using namespace ost;
#endif

// Test child thread destroying before father
//
class Child: public Thread
{
public:
       Child()
       { }
       void run()
       {
               cout << "child start" << endl;
               Thread::sleep(6000);
               cout << "child end" << endl;
       }
       void final()
       {
               delete this;
       }
};

class Father: public Thread
{
public:
       Father()
       { }
       void run()
       {
               cout << "father start" << endl;
               Thread::sleep(2000);
               Thread *th = new Child();
               th->start();
               Thread *th2 = new Child();
               th2->start();
               Thread::sleep(10000);
               cout << "father end" << endl;
       }
       void final()
       {
               delete this;// - not used since detached threads self delete
               // reset memory to test access violation
               //memset(this,0,sizeof(*this));
       }
};

int main(int argc, char* argv[])
{
   Thread::sleep(2000);
   Father *th = new Father();
       th->start();
       Thread::sleep(20000);

       return 0;
}






reply via email to

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