Article View: borland.public.cppbuilder.internet.web
Article #429TCppWebBrowser use of memory (consuming it all)
From: Eduardo Jauch
Date: Sun, 04 Feb 2007 14:47
Date: Sun, 04 Feb 2007 14:47
160 lines
5073 bytes
5073 bytes
Hi :)
Me again ;)
I was able to create some code looking here, google groups and a link
that Remy posted here on the Interfaces (MUCH useful! Thanks Remy)...
The program works fine.
But the amount of memory "allocated" by the process always incrase...
Because I'm a newbe to programming with TCppWebBrowser, I can't find
where this memory is been allocated and not released.
Like you can see (if I'm wrong, please, teel me), I'm not allocating
memory myself.
Anyway,
To work out this memory usage problem, I create a simpler version of the
program. I show you the code below.
After click the "iniciar_bt" button, only these three functions are
executed:
BrowserNavigateComplete2
EncontrarFrame
BrowserDocumentComplete
I'm try to debug, while observing the use of memory (from task maneger)
I figured that when the program leaves the function
BrowserDocumentComplete, the memory that was "catch" when enter, is not
all freed then..
Any ideas of what I'm doing wrong?
//---------------------------------------------------------------------------
void __fastcall TjanelaPrincipal::iniciar_btClick(TObject *Sender)
{
Browser->Navigate(WideString("www.visto-eua.com.br"));
}
//---------------------------------------------------------------------------
IHTMLDocument2 *TjanelaPrincipal::EncontrarFrame(WideString frame_name)
{
IHTMLDocument2 *FrameDoc;
FrameDoc = NULL;
if( Browser->Document )
{
IHTMLDocument2 *Doc = NULL;
Browser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&Doc);
if( Doc )
{
IHTMLFramesCollection2 *Frames;
Doc->get_frames(&Frames);
Doc->Release();
if( Frames )
{
TVariant IndexOrName = frame_name;
TVariant Frame;
Frames->item(&IndexOrName, &Frame);
Frames->Release();
if( (V_VT(&Frame) == VT_DISPATCH) && (V_DISPATCH(&Frame) != NULL) )
{
IHTMLWindow2 *Window;
V_DISPATCH(&Frame)->QueryInterface(IID_IHTMLWindow2,(LPVOID*)&Window);
if( Window )
Window->get_document(&FrameDoc);
Window->Release();
}
}
}
}
return FrameDoc;
}
//---------------------------------------------------------------------------
void __fastcall TjanelaPrincipal::BrowserNavigateComplete2(TObject *Sender,
LPDISPATCH pDisp, Variant *URL)
{
if (!CurDispatch)
CurDispatch = pDisp; // save for comparison
}
//---------------------------------------------------------------------------
void __fastcall TjanelaPrincipal::BrowserDocumentComplete(TObject *Sender,
LPDISPATCH pDisp, Variant *URL)
{
IHTMLDocument2 *FrameDoc;
TVariant FrameName("iContent");
IHTMLElementCollection *All;
IDispatch *Disp;
IHTMLInputElement *pInput;
if (pDisp == CurDispatch)
{
CurDispatch = NULL;
FrameDoc = EncontrarFrame(WideString("iContent"));
if( FrameDoc )
FrameDoc->get_all(&All);
else
return;
if(!All)
{
FrameDoc->Release();
return;
}
if(pagina == 1)
{
pagina = 2;
FrameDoc->Release();
All->Release();
Browser->Navigate(WideString("http://www.visto-eua.com.br/agendamento-web/login?redirect=/agenciadores.do"),
NULL, &FrameName);
}
else if(pagina == 2)
{
All->item(TVariant(WideString("login")), TVariant(0), &Disp);
if( !Disp ) return;
Disp->QueryInterface(IID_IHTMLInputElement, (LPVOID*)&pInput);
Disp->Release();
if( !pInput ) return;
pInput->put_value(WideString ("MyLogin"));
pInput->Release();
All->item(TVariant(WideString("senha")), TVariant(0), &Disp);
if( !Disp ) return;
Disp->QueryInterface(IID_IHTMLInputElement, (LPVOID*)&pInput);
Disp->Release();
if( !pInput ) return;
pInput->put_value(WideString("MyPassword"));
pInput->Release();
pagina = 1;
FrameDoc->Release();
All->Release();
Browser->GoBack();
}
}
}
Technical Details
Message-ID:
<45c5f1bc@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: feeec,8aa0e5fdfe5fb256,start X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Sun, 04 Feb 2007 12:47:30 -0200 From: Eduardo Jauch <eduardo.jauch@gmail.com> User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.web Subject: TCppWebBrowser use of memory (consuming it all) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 201.35.53.164 Message-ID: <45c5f1bc@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1170600380 201.35.53.164 (4 Feb 2007 06:46:20 -0800) Lines: 160 Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail