我想从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 ;}这是为什么呢?理论上说这个函数执行完毕就应当释放掉内存啊?可事实不是这样的,申请的内存释放不掉。知道程序退出才释放掉。
解决方案 »
- 关于API HOOK的问题
- 请教mfc中两个函数的详细使用 afxlockglobals 和afxunlockglobals
- 如何在VB中使用API画出一个窗口(VB技术区的人太水)在线等待
- CreateProcess 的问题 着急!!!!
- PPP Terminate-Request Frame 关于协议的问题 100分
- 准备辞职做共享,放分
- 怎么把中文版的VC++6。0改成英文的?
- 用share dll方式编译出来的程序会有什么问题?
- CListView单文档视图,当点击新建时,原来ListView里面的内容如何清除?
- 求助:运行到CShowDibDoc* pDoc=GetDocument()的时候没法继续了?
- 谁能帮帮我 根据下面协议怎么初始化
- MFC中有没有包含"WritePrivateProfileString"或类的类
CFtpFileFind好像没有问题,我试着把它close还是一样