logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christophe de VIENNE <cdevie...@alphacent.com>
Subject Re: Memory leaks?
Date Fri, 13 Aug 2004 14:44:14 GMT
Eric Rosenquist wrote:

>The per-thread map never seems to get
>deleted anywhere when the thread terminates.
>  
>

I had a closer look to threadspecificdata.cpp. It seems that no mecanism 
is provided to allow an automatic deletion of objects on thread 
termination. Adding it would be a more clean and reliable solution to 
this memory leak.
This can easily be done, at least with pthreads, with a templated class 
looking like :

template<class T>
class TSD
{
    public:
       TSD(): key(0) {
            pthread_key_create(&key, &destr_function);
       }

       // ...

    private:
        static void destr_function(void * data) {
             delete static_cast<T*>(data);
        }
        pthread_key_t key;
};


If it's possible to do it with msthreads (I guess so) I'd like to 
propose a more complete TSD handling solution.
If we do it, we can profit of the occasion to use the pimpl idiom on 
ThreadSpecificData, which would solve the HAVE_PTHREAD macro problem, at 
least for this file.

Any idea/suggestion welcome,


Christophe


Mime
View raw message