protobuf-net itself isn't going to keep hold of the old messages - indeed, if it was doing that, the GC.Collect
wouldn't have helped.
The first thing I can see is that the hot loop waiting on DataAvailable
is really expensive; that could perhaps be interfering with GC
. The second thing I can see is that you can probably release the object at o
before sleeping; as a random thing to try, perhaps:
using (NetworkStream stream = m_Stream)
{
object o;
while (Serializer.NonGeneric.TryDeserializeWithLengthPrefix(
stream, PrefixStyle.Base128,
Utilities.CommunicationHelper.resolver, out o))
{
if (o != null)
{
//TODO: Do something with the incoming protobuf object
// clear o, just to give GC the very best chance while we sleep
o = null;
}
Thread.Sleep(1); // <=== not sure why you want to sleep here, btw
}
}