lidgren-network-gen3 icon indicating copy to clipboard operation
lidgren-network-gen3 copied to clipboard

Outgoing message pooling

Open cswiedler opened this issue 7 years ago • 2 comments

We're using Lidgren under Unity with message / storage pooling enabled. I would assume that this would cause Lidgren to re-use outgoing messages so that after a short time, there are no more allocations, but that doesn't appear to be the case. Some messages, at least, are getting recycled, but apparently not all of them, because over time GetStorage() continues to allocate new buffers and m_bytesAllocated grows larger and larger. If I put simple tracking inside GetStorage() and Recycle(), over time the number of GetStorage() calls exceed Recycle().

I've put a breakpoint where Recycle() checks for fragments, and that's not getting hit. Do you have any ideas for how we can reduce our memory allocations using Lidgren?

cswiedler avatar Aug 15 '17 21:08 cswiedler

It looks like this only happens with reliable messages; unreliable messages don't show the same behavior. We're going to switch to unreliable messages (we just haven't quite yet finished the higher-level support for dropping packets) but it would be nice to make sure pooling works properly even with reliable messages.

cswiedler avatar Aug 15 '17 21:08 cswiedler

I've also noticed that Lidgren is causing GC Allocs despite pooling/recycling.

cclogg avatar Apr 06 '19 01:04 cclogg