Advertisement

Vector causing mem leak?!?!

Started by December 19, 2002 12:50 PM
1 comment, last by Sand_Hawk 21 years, 10 months ago
I have a class CServer and a class CClient. When I start the server I create several slots for the clients and set a pointer inside CClient towards a vector inside CServer. Here is some code to show what I do exactly:
  
struct tMessage
{
    int    iFromUser;
    int    iFlags;
    string szMessage;
};

class CClient
{
public:
     Execute();
     vector<tMessage> *pMsgQueue;
};

class CServer
{
public:
    CServer() {}
    ~CServer() {}
    Startup(...);
    ....
private:
    ClientData
    vector<tMessage> MessageQueue;
};
  
When I start the server, I do this:
  
CServer::Startup(...)
{
    ClientData = new CClient[iMaxConn];
    for (int i = 0; i < iMaxConn; i++)
        ClientData[i].pMsgQueue = &MessageQueue
}
  
When I close my client thread in the server, I do this:
  
CClient::Execute()
{
    //other shutdown code

    pMsgQueue->push_back(Msg); // Push in msg queue

    return (0);
}
  
Why I comment the line of code with the push_back, I don''t get a mem leak, and if I use it, there are 24 bytes missing. What is causing this? Sand Hawk ---------------- -Earth is 98% full. Please delete anybody you can.
My Site
----------------(Inspired by Pouya)
What is this ''Msg'' that you add to the vector in CClient::Execute?
Advertisement
Well, I found out that calling the destructor of the vector releases all the memory. I dunno why it didn''t clean up after I called erase.

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site
----------------(Inspired by Pouya)

This topic is closed to new replies.

Advertisement