Re: Memory leak with socket BeginReceive?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Update. This leak is a byproduct of two things. First, all allocation
in the CLR takes place at the top of the heap. Second, the GC can't
compact memory below the highest (newest) pinned object. Every call to
socket.BeginReceive pins the buffer object that you pass in. It remain
pinned for a long time (until the data arrives on the socket), followed
by a brief instant between EndReceive and the next BeginReceive when
it's unpinned, and you process received data. Only if a GC occurs
during the brief instant, AND it's on the highest pinned buffer, will
memory be compacted. That's why a Thread.Sleep helps.

The real fix is to allocate a fixed pool of buffers early during
program startup. They're pinned but low in memory. Or use .Net 2.0
which is supposed to fix this problem :)

.



Relevant Pages

  • Re: Alternative to C for system programming
    ... be blocks of memory that are GC and nonGC, ... to call it a systems programming language with GC. ... Just make sure your disk buffer or whatever is ... allocation of memory: I/O module thinks it will need more memory ...
    (comp.programming)
  • Re: callocs, call by ref and function returning in C
    ... > memory allocation and freeing). ... clobbering buffer, so you can never free that memory again. ... you exit without freeing up resources. ...
    (comp.programming)
  • Re: Attention Windows Users
    ... > how there could be a buffer overflow. ... > memory. ... A "dynamic allocation" is one that occurs at run-time. ... a buffer overflow can occur with either a dynamic or static ...
    (rec.aviation.piloting)
  • Re: return a string
    ... Declare a static array of char in your ... mallocmemory for the string inside your function ... >> provide a way to use an alternative allocation function. ... Pass an already allocated buffer and its size to your function. ...
    (comp.lang.c)
  • Re: How to release heap memory that is marked as free
    ... As I said, fragmentation is a very serious problem, and one of the most serious problems ... my allocator was accused of using massive amounts of memory. ... I'm going to have to re-think the memory allocation that I'm ... process's 'working set'. ...
    (microsoft.public.vc.mfc)