[Mono-devel-list] question about System.Net.Socket's memory usage

Davy Brion ralinx at pandora.be
Sat Jun 26 13:33:37 EDT 2004


Hi,

i've noticed that receiving data from a socket in a loop increases memory 
usage slowly.  It's like the entire stream of data is being kept in memory. 
Once you read data from a socket, and the byte array which contains the data 
goes out of scope, shouldn't that data be removed from the memory?

I have an application which runs on both Windows (with MS.NET) and Linux 
(using Mono obviously).  The application connects to a bunch of IRC servers.
The Windows version never had any memory problems, the Linux version has 
always had a problem with memory usage... specifically in that it keeps 
eating more and more memory the longer you keep the application running.   
But it's the same code.  I've noticed this behaviour ever since i tried Mono 
for the first time (that was around Mono 0.26 i think) but i've only now 
decided to track it down.  As it turns out, i believe the Socket class is 
responsible.

I wrote a small test application which shows what i'm talking about... it will 
connect to the Freenode irc server and join some popular channels and then it 
will just read the incoming data in a loop.  the incoming data is just being 
read from the socket, it goes out of scope shortly after calling 
Socket.Receive yet memory usage keeps increasing.  Obviously, in this case 
the problem isn't very big because it's only one connection.  But it's 
noticable if you keep an eye on the memory usage and as you can imagine, this 
problem becomes quite a pain in the neck once you start connecting to more 
than 10 high traffic irc servers.

So like i said, it looks like the socket is keeping the entire stream in 
memory or something like that... but shouldn't that data be removed from 
memory once you've read it from the socket?  Again, with MS.NET this isn't a 
problem.

Thanks in advance.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.cs
Type: text/x-c++src
Size: 2104 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040626/45f0ed41/attachment.bin 


More information about the Mono-devel-list mailing list