CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jan 2010
    Posts
    3

    Sockets + Windows Server 2008 = Memory Leak

    Hello,

    We have a small service shows continuous nonpaged pool bytes increase from the moment it is started. This is only on a 2008 server (all the others work fine).

    The service basically connects a socket to a client to see if it's successful and then closes (most code omitted):

    Code:
    Try
        client = New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
        client.LingerState = New System.Net.Sockets.LingerOption(False, 0)
        client.ReceiveBufferSize = 1024
        client.SendBufferSize = 1024
        client.Connect(address, _port)
    Catch
    
    Finally
        'Release the socket.
        If client IsNot Nothing AndAlso client.Connected Then
            client.Shutdown(System.Net.Sockets.SocketShutdown.Both)
            client.Disconnect(True)
            client.Close(5)
            client = Nothing
        End If
    It does also call an asynchronous BeginReceive() but I've commented that part out and the leak is still evident. The code is inside a timer, and gets called by a configurable amount. I've tried many things in code, and also upgrading the project to use the 3.5 Framework combined with the suggestions here:

    http://msdn.microsoft.com/en-us/magazine/cc163356.aspx

    But it still increases by 15.36 bytes every iteration. Some resources just aren't being released?!

    Many thanks in advance,

    Phil
    Last edited by Torrs; February 1st, 2010 at 07:12 AM. Reason: Put code in code blocks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured