Memory Leak with Sockets RRS feed

  • Question

  • Hi.
    I have a problem :(

    My program creates and detroys sockets many times per minute. But the first time I Read or Write every socket, it reserves 72KB of private bytes and when I destroy it... it dont releases that 72KB...
    I dont know why...

    There is an example code wich have this problem. Put it in the click event of an button and everytime you click it.. the private bytes will increase 72KB

            Dim testBuffer(100) As Byte 'any size same problem 
            Dim testSocket As New Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp) 
            testSocket.Connect("mail.multiled.com.ar", 110) 'test host 
            testSocket.Receive(testBuffer) 'here the 72KB are reserved (the same problem with .Send) 
            'Try with this, but the problem stills 
            testSocket = Nothing 
            testBuffer = Nothing 

    I'm using: .net 2.0 on Windows XP SP2 (I use Process Explorer Sysinternals to view the private bytes)

    Sorry my bad english..


    • Edited by StitcHWandeR Friday, June 27, 2008 7:58 PM corrections
    • Changed type Bruno Yu Wednesday, July 2, 2008 7:59 AM Change the unreplied thread to Comment.
    • Changed type StitcHWandeR Friday, July 18, 2008 4:41 PM im back
    • Changed type StitcHWandeR Friday, July 18, 2008 4:42 PM i have the solution
    Friday, June 27, 2008 7:57 PM

All replies

  • Kirill,

    I assume you have .NET 2.0 sp 1 installed.
    Have you tried building the project release mode with optimizations turned on?

    Friday, June 27, 2008 8:59 PM
  • So, if you put this code in a loop, you should be able to crash your program with an OutOfMemory exception, right?  How many iterations does it take?
    Hans Passant.
    Saturday, June 28, 2008 12:40 AM
  • We are changing the issue type to “Comment” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by editing your initial post and changing the radio button at the top of the post editor window. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

    Thank you!

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, July 2, 2008 8:01 AM
  • I have intalled the SP1 and now works OK

    Thank you ;)
    Mr. K
    Friday, July 18, 2008 4:45 PM