我想从FTP上下载东西,放在本地。结果总是存在内存泄露,很是郁闷,代码在下面:
void CFTP_MEM_TESTDlg::OnBnClickedOk()
{FTP_INFO stuFTPInfo;stuFTPInfo.iFtpPort = 21;
stuFTPInfo.strFileName = _T( "ccaccbccc" );
stuFTPInfo.strFtpIP = _T( "192.168.0.30" );
stuFTPInfo.strFtpPwd = _T( "ccaccbccc" );
stuFTPInfo.strFtpUserName = _T( "ccaccbccc" );
stuFTPInfo.strPath = _T( "ccaccbccc" );
CInternetSession* pInetSession = new CInternetSession( NULL, 1, PRE_CONFIG_INTERNET_ACCESS );if ( pInetSession == NULL )
{
return ;
}CFtpConnection* pFtpConnection = pInetSession->GetFtpConnection( stuFTPInfo.strFtpIP,
stuFTPInfo.strFtpUserName,
stuFTPInfo.strFtpPwd,
stuFTPInfo.iFtpPort );CString strFTPPath = _T( "FTP_FOLD" );pFtpConnection->SetCurrentDirectory( strFTPPath );CFtpFileFind finder( pFtpConnection );BOOL bWorking=finder.FindFile( _T("*") );while ( bWorking )
{
bWorking = finder.FindNextFile();CString strFileName = finder.GetFileName();int iPos = strFileName.Find( _T( "." ) );CString strFlag = strFileName.Mid( iPos + 1, strFileName.GetLength() );if ( strFlag == _T( "jpg" ) )
{
CString strLocolFile = _T( "C:\\Debug\\" ) + strFileName;pFtpConnection->GetFile( strFileName, strLocolFile );
}}pFtpConnection->Close();
delete pFtpConnection;pInetSession->Close();
delete pInetSession;return ;}这是为什么呢?理论上说这个函数执行完毕就应当释放掉内存啊?可事实不是这样的,申请的内存释放不掉。知道程序退出才释放掉。
void CFTP_MEM_TESTDlg::OnBnClickedOk()
{FTP_INFO stuFTPInfo;stuFTPInfo.iFtpPort = 21;
stuFTPInfo.strFileName = _T( "ccaccbccc" );
stuFTPInfo.strFtpIP = _T( "192.168.0.30" );
stuFTPInfo.strFtpPwd = _T( "ccaccbccc" );
stuFTPInfo.strFtpUserName = _T( "ccaccbccc" );
stuFTPInfo.strPath = _T( "ccaccbccc" );
CInternetSession* pInetSession = new CInternetSession( NULL, 1, PRE_CONFIG_INTERNET_ACCESS );if ( pInetSession == NULL )
{
return ;
}CFtpConnection* pFtpConnection = pInetSession->GetFtpConnection( stuFTPInfo.strFtpIP,
stuFTPInfo.strFtpUserName,
stuFTPInfo.strFtpPwd,
stuFTPInfo.iFtpPort );CString strFTPPath = _T( "FTP_FOLD" );pFtpConnection->SetCurrentDirectory( strFTPPath );CFtpFileFind finder( pFtpConnection );BOOL bWorking=finder.FindFile( _T("*") );while ( bWorking )
{
bWorking = finder.FindNextFile();CString strFileName = finder.GetFileName();int iPos = strFileName.Find( _T( "." ) );CString strFlag = strFileName.Mid( iPos + 1, strFileName.GetLength() );if ( strFlag == _T( "jpg" ) )
{
CString strLocolFile = _T( "C:\\Debug\\" ) + strFileName;pFtpConnection->GetFile( strFileName, strLocolFile );
}}pFtpConnection->Close();
delete pFtpConnection;pInetSession->Close();
delete pInetSession;return ;}这是为什么呢?理论上说这个函数执行完毕就应当释放掉内存啊?可事实不是这样的,申请的内存释放不掉。知道程序退出才释放掉。
CFtpFileFind好像没有问题,我试着把它close还是一样