Jump to content
abe

FBufHandler keeps data in memory

Recommended Posts

Hello, guys.

 

I am developing an application in Delphi where I'm using ICS8. My application acts as a SocketServer, its clients are TWSocketClient objects.

The thing is, I'm trying to send some files (~100MB) over TCP and somewhere inside the TWSocketClient instance the data is being kept inside some buffer even after it's sent and received by the client, causing some sort of a leak. (If I destroyed the Client object without destroying the inherited part, the memory was still allocated)

And I'm talking about some memory use (over 100MB per client when idle). Whenever the client is disconnected, the memory is freed.

The first chunks of data are being sent with RealSend, when the AllSent turns into False, I use the inherited Send.

 

Can someone shed some light on what am I missing?

I tried checking for the SocketSndBufSize and SocketRcvBufSize properties and they're both set at their default value before and after the memory leak. BufSize is 1460.

Checking the code, I got a feel like my data is being put inside FBufHandler's FFreeList and being kept there forever.

 

For contract reasons, I can't share any code snippet.

 

Thanks.

Abe

Edited by abe

Share this post


Link to post

Data to be sent in a TWSocket (Any derived class) is stored in a dynamic buffer until it can be sent. Once a chunk of data has been sent, the memory is reused. This is used to implement the asynchronous nature of TSWocket. No matter how much data you send by calling one of the send() methods, data is buffered and send() returns immediately while your data is sent in the background at the speed the network accept it. So if you send 100MB of data, for example in a loop reading a 100MB file, it will then be saved entirely in memory. If you don't like this behaviour for any reason, sent on data chunk at once and use OnDataSent event to read your next data chunk and send it.

 

On receive, your application get an OnDataAvaiable event. No data is buffered by the component. You MUST read all data available from the OnDataAvailable event handler.

 

 

Share this post


Link to post

Hello, François.

 

First of all, it's a pleasure talking to you.

Thank you for enlightening me on this process, your explanation was really helpful.

 

Abe.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×