Re: CInternetSession
On Sun, 27 May 2007 17:06:14 +0200, SOCAR <socar@iv.pl> wrote:
I have tried below code before (which comply with your questions)
try{
while(true)
{
CInternetSession csiSession;
CHttpFile* MyFile = (CHttpFile*)
csiSession.OpenURL(_T("http://www.google.com"));
if( MyFile != NULL )
{
MyFile->Close();
delete MyFile;
}
}
}
catch(CInternetException*
e){MessageBox(NULL,_T("goterror"),_T("goterror"),MB_OK);
}
Sleep(10000);
}
but still I receive "First Chance Exception" warning. Also app have memory
leak about 4KB per loop (shown in TaskManager). The catch block is not
utilized in any way - app dont raise any exceptions during execution. Also
it returns a normal data from the http request via CStdioFile or CHttpFile.
Only thing is that it got this memory leaks, which "dissapears" when I
comment out "OpenURL" Line.
The "First Chance Exception" message usually indicates nothing harmful. See
this KB article for more on the subject:
First and second chance exception handling
http://support.microsoft.com/kb/105675
Your catch clause isn't being entered because something else is handling
the exception, probably a C++ exception handler established by OpenURL or
one of the functions it calls. You can configure the debugger to stop at
first chance exceptions or simply trace into the function to determine the
source of the exception, but what you're observing is exactly what you'd
expect to see if OpenURL (or a function it calls) throws an exception and
catches it internally. This is all roughly equivalent to a function
printing a message visible in the debugger whenever it returns an error
code, whether or not the error is eventually handled.
As for your memory leak, your loop is not returning to the application
message loop, so MFC is not performing its idle-time processing, during
which it frees temporary objects. I'd guess that's the cause, and you can
test this hypothesis by adding the following to the end of your loop:
// I'm assuming you're doing this in your app's primary thread.
LONG idleCount = 0;
while (AfxGetApp()->OnIdle(idleCount++))
continue;
If the leak doesn't go away, try using MFC's CMemoryState class to
determine the objects you're leaking.
--
Doug Harrison
Visual C++ MVP