No_Excuses
May 24th, 2002, 07:10 PM
I have created a simple project using the wizard. It is a simple dialog and which has ok and cancel buttons. When I exit everything is ok (when you look into the output window (The program '[1472] test1.exe: Native' has exited with code 0 (0x0).).

Note the code snippet for the "ok" run:

CInternetSession m_session;
CStdioFile *m_pfile;

#if 0
m_pfile = m_session.OpenURL("http://www.codeguru.com");
if (m_pfile != NULL)
m_session.Close();
#endif

I then commented out the #if/endif as follows:

CInternetSession m_session;
CStdioFile *m_pfile;

//#if 0
m_pfile = m_session.OpenURL("http://www.codeguru.com");
if (m_pfile != NULL)
m_session.Close();
//#endif

The following is seen in the output window:

Detected memory leaks!
Dumping objects ->
{83} normal block at 0x002F7BC8, 20 bytes long.
Data: < .| > 10 FF 2E 7C 03 00 00 00 03 00 00 00 01 00 00 00
{82} normal block at 0x002F7B78, 18 bytes long.
Data: < .| > 10 FF 2E 7C 01 00 00 00 01 00 00 00 01 00 00 00
{81} normal block at 0x002F7B18, 33 bytes long.
Data: < .| > 10 FF 2E 7C 10 00 00 00 10 00 00 00 01 00 00 00
{80} normal block at 0x002F2A60, 18 bytes long.
Data: < .| > 10 FF 2E 7C 01 00 00 00 01 00 00 00 01 00 00 00
inet.cpp(560) : {79} client block at 0x002F7A90, subtype c0, 76 bytes long.
a CHttpFile object at $002F7A90, 76 bytes long
Object dump complete.
The program '[1460] test1.exe: Native' has exited with code 0 (0x0).

I have searched quite a bit for others with this same problem and have seen people ask for an answer but they never got one.

Here are my questions:

1) Can something be done to fix the memory leak and if the answer is yes what is it?

2) All I do is read the html from the specified URL (not included in my simple example/test above). If there is a better alternative would you please suggest it and if possible give a simple example or reference as to where I can go to view the solution.

Thanks in advance,

Todd G.

NigelQ
May 24th, 2002, 07:32 PM
This should remove the memory leak...


CInternetSession m_session;
CStdioFile *m_pfile;

//#if 0
m_pfile = m_session.OpenURL("http://www.codeguru.com");
if (m_pfile != NULL)
{
m_pfile->Close();
delete m_pfile;
}
m_session.Close();
//#endif


Hope this helps,

- Nigel

No_Excuses
May 24th, 2002, 07:41 PM
Thanks for the response!!! It does eliminate the memory leak.

I do get the following warning:

Warning: destroying an open CInternetFile with handle 00CC000C

I tried putting the delete before and after the close session and got the same warning either way.

{
m_session.Close();
delete m_pfile;
}

and

{
m_session.Close();
delete m_pfile;
}

Any other comments to eliminate this warning?

Thanks in advance,

Todd G.

NigelQ
May 24th, 2002, 07:43 PM
I edited the snippet of code (not before you saw it, it seems). Try the new version above.

- Nigel

No_Excuses
May 24th, 2002, 07:47 PM
Thanks for you quick reply!! No more leaks or warnings!

Todd G.


** New로 선언되어지고 delete를 다 해주었는데.. memory leak이 발생하여 걱정하였는데
    구글에서 찾아보니..... 해결점을 찾았다. 문제는 CHttpfile로 포인터형으로 인스턴스 형으로 선언되어진것을
     delete 해주니까 해결이 되었다 -.-;;;
Posted by 모과이IT
,