FastBinaryEncoding icon indicating copy to clipboard operation
FastBinaryEncoding copied to clipboard

Leak if sending data in a loop.

Open forlayo opened this issue 1 year ago • 2 comments

I am trying to check net capacity and I am doing:

    private async Task FakeDataSource()
    {
        await Task.Delay(500);
        Random rnd = new Random();
        var randomBytes = new byte[64000]; // 64k
        rnd.NextBytes(randomBytes);

        while (true)
        {
             var packet = new VideoPacket(1280, 720, new MemoryStream(randomBytes , 0, randomBytes .Length, false, true));
             _client.Send(packet);
        }
    }
  • _client is SimpleProtoClient as in the example.
  • VideoPacket is a message defined as
message VideoPacket
{
    uint16 width;
    uint16 height;
    bytes data;
}

Memory goes high in few seconds taking some Gb and then it crashes, I can see that an object of type Buffer has got all the RAM. As a weird note, If I add "await Task.Delay(1);" after the Send() it doesn't crash (but obviously is sending just a fraction of what's possible ).

What I am doing wrong ? How can I send as much as possible?

forlayo avatar Jan 19 '23 23:01 forlayo