Boost logo

Boost Users :

From: Elisabeth Benoit (elisabeth.benoit_at_[hidden])
Date: 2006-07-03 16:32:18


Hello,

I'm sending this message a second time (I didn't receive any response and still
have this problem)

I'm using boost::bind and boost::signal with VC6. VC6 is detecting some memory
leak for a certain type of signal.connect(). I've done a little test program to
check if the problem was due to some bug or special configuration in my main
program, but the memory leaks are still detected in the test situation.

Let me explain the structure of my test program. I have a main, and in the main,
an object CCloneAppRecipe named clone. The class CCloneAppRecipe contains a
member m_PtrTestMem (a shared pointer, but a raw point or an object does the
same thing) of the class CTestMem. CTestMem contains 3 instances of the class
CTestTab, and the class CTestTab contains a boost signal

typedef boost::signal0<void> TypeSignalTest;
TypeSignalTest m_SignalTest;

In my main, I invoke clone.connectPtrTestMem().
clone.connectPtrTestMem() then invokes
CTestMem::ConnectSignalTriplePtrTab(boost::bind(&CloneAppRecipe::test, this));
ConnectSignalTriplePtrTab() then invokes ConnectSignal(TypeSignalTest::slot_type
slot) for each of the 3 instances of the class it contains.
ConnectSignal then calls m_SignalTest.connect(slot).

And I have a memory leak: 2 blocks of 16 bytes. If I connect only one instance
of CTestTab, no leak. Two instances, one leak of 16 bytes. Three, two leaks of
16 bytes, and so on.

I connect the m_SignalTest with a CCloneAppRecipe's slot. If I connect it to a
CTestMem slot, I have no leak. Or if I place 3 instances of CTestTab directly
in the CCloneAppRecipe class (so I don't use CTestMem anymore), I have no leak.
But that's not what I need to do. I've tested plenty of variations
(shared_pointer or object, etc.) Does anybody have a clue.

Thanks

#include "stdafx.h"
#include "CloneAppRecipe.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

int main()
{
        CloneAppRecipe t;
        // cree un leak
        t.connectPtrTestMem();
        getchar();
        return 0;
}

void CloneAppRecipe::connectPtrTestMem()
{
        //m_ptrTestMem is a boost::shared_ptr
        m_ptrTestMem->ConnectSignalTriplePtrTab(boost::bind(&CloneAppRecipe::test,
this));

}

void CloneAppRecipe::test() const
{
}

void CTestMem::ConnectSignalTriplePtrTab(const TypeSignaTest::slot_type& slot)
{
        //m_ptrTestTab are boost::shared_ptr
        m_ptrTestTab1->ConnectSignal(slot);
        m_ptrTestTab2->ConnectSignal(slot);
        m_ptrTestTab3->ConnectSignal(slot);
}

void CTestTab::ConnectSignal(const TypeSignalTest::slot_type& slot)
{
        m_SignalTest->connect(slot);
}

CTestTab::~CTestTab()
{
        m_SignalTest->disconnect_all_slots();
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net