Boost logo

Boost Users :

From: tankbattle (tankbattle_at_[hidden])
Date: 2006-09-06 09:02:22


I’ve written a MFC based console application to test boost.thread library.
However, IDE suggested that there are memory leaks in the program. All that I’
ve done is creating a class A which implements operator () and declared an
instance of boost::thread which make use of A. How can that make memory leak?
My IDE is vs.net 2003 and my OS is windows xp sp1.
My code is as follows:

// threadmemleak.cpp :
//

#include "stdafx.h"
#include "threadmemleak.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include <boost\thread\thread.hpp>

class A
{
public:
        A()
        {
        }
        void operator() ()
        {
                //Sleep(1000);
        }
};

// Single application object
CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
        int nRetCode = 0;

        // Initialize MFC and display error on failure
        if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
        {
                // TODO: Correct your code so as to meet your need
                _tprintf(_T("Fatal error: MFC initialization failed\n"));
                nRetCode = 1;
        }
        else
        {
                // TODO: Write your own code
                A a;
                boost::thread thread1(a);
                thread1.join();
        }

        return nRetCode;
}

 and output of IDE is

Detected memory leaks!
Dumping objects ->
{153} normal block at 0x00376A70, 24 bytes long.
 Data: < \ > B0 5C 14 00 FF FF FF FF 00 00 00 00 00 00 00 00
{152} normal block at 0x00376CE0, 8 bytes long.
 Data: <pj7 > 70 6A 37 00 01 CD CD CD
Object dump complete.


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