So I'm writing a program (MFC) that connects to a server w/ windows sockets (YUCK I know). I left it running as part of an endurance test the other day, and my PC ran out of virtual memory. Odd eh? So I ran it again using task manager and noted that it's taking approx. 5,000k or memory everytime it recives and doesn't release the memory until the program is killed. I assume recieves because the amount of memory it takes up is related to how big
char *pBuf = new char[1000025];
is. (See code below) The following is code from the ::OnRecive function in my program.
{
char *pBuf = new char[1000025];// yeah yeah i know it's huge!!
int iBufSize = 10000024;
int iRcvd;
CString strRecvd;
// Receive the message
iRcvd = m_sConnectSocket.Receive(pBuf, iBufSize);
// Did we receive anything?
if (iRcvd == SOCKET_ERROR)
{
}
else
{
// Truncate the end of the message
pBuf[iRcvd] = NULL;
// Copy the message to a CString
strRecvd = pBuf;
m_pBuf = pBuf;
m_strOutput = strRecvd;
// Sync the variables with the controls
// UpdateData(FALSE);
}
}
So!!! Here in lies the question. Why does it keep taking memory and not releasing it (until the program is killed) and how to I get it to release the memory?