Article View: borland.public.cppbuilder.internet.socket
Article #4992Re: Possible memory leak with TIdTCPClient?
From: Drew
Date: Tue, 09 Nov 2004 13:58
Date: Tue, 09 Nov 2004 13:58
92 lines
3801 bytes
3801 bytes
Thank you for all these comments.
I am trying to isolate the line of code, but whatever I change affects the
actual code that is being executed, and so I end up with a different result.
I will persevere.
Two other questions on this subject, if I may:
1. When I try to connect, I specify a connect timeout of 5000msecs, but the
timeout exception isn't raised until about 21 seconds after the connection
attempt. Any ideas why?
2. If a connection attempt fails, do I need to do anything to tidy up the
connection?
Thanks
Andrew
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:4190014c$1@newsgroups.borland.com...
>
> "Drew" <aemsley@brightwell.org.uk> wrote in message
> news:418ff4b9$1@newsgroups.borland.com...
>
> > Over time, the mmory used by my application increases, increasing
> > from about 9Mb at start-up to more than 100 Mb after a day or so.
> > I am fairly certain that it is the Indy component that is causing the
> problem
>
> It would help if you could isolate where the supposed memory leak is
> actually occuring. Please try to find the actual line in your thread code
> that is causing it.
>
> > if ((!GetConnected()) | (!CommOpen))
>
> You have a typo in that line. It should be using the "||" operator, not
the
> "|" operator.
>
> > bool IPConnected = true; //Assume OK until we find otherwise
>
> Rather than duplicating all of that connecting code, you could just call
> Open().
>
> > tempBuff = new char[dataLength];
> >
> > m_clientSocket->ReadBuffer(tempBuff, dataLength);
> > delete[] tempBuff;
>
> You don't need to read the buffer. Just clear it directly:
>
> m_clientSocket->InputBuffer->Clear();
>
> > m_clientSocket->OpenWriteBuffer();
>
> You are not clearing the write buffer if an error occurs.
>
> try
> {
> m_clientSocket->WriteBuffer(buffer, ByteCount);
> m_clientSocket->CloseWriteBuffer();
> }
> catch(const Exception &)
> {
> m_clientSocket->CancelWriteBuffer(); // <-- add this
> Close();
> return eTCPwriteFailed;
> }
>
>
> > tempBuff = new char[dataLength];
> >
> > m_clientSocket->ReadBuffer(tempBuff, dataLength);
> >
> > memcpy(&ReplyBuf[Index], tempBuff, dataLength);
>
> Why are you using a temporary buffer? You could just read into your
target
> buffer directly:
>
> m_clientSocket->ReadBuffer(&ReplyBuf[Index], dataLength);
>
> > if (Index == ReplySize)
>
> Where is ReplySize being set to? Why are you not simply passing ReplySize
> to ReadBuffer() directly and read the entire reply in a single operation?
>
>
> Gambit
>
>
Technical Details
Message-ID:
<4190cccb$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news2.euro.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<418ff4b9$1@newsgroups.borland.com> <4190014c$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,357e5d574910e956 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Drew" <aemsley@brightwell.org.uk> Newsgroups: borland.public.cppbuilder.internet.socket References: <418ff4b9$1@newsgroups.borland.com> <4190014c$1@newsgroups.borland.com> Subject: Re: Possible memory leak with TIdTCPClient? Date: Tue, 9 Nov 2004 13:58:18 -0000 Lines: 94 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 81.137.221.84 Message-ID: <4190cccb$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1100008651 81.137.221.84 (9 Nov 2004 05:57:31 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news2.euro.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail