473,387 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Strange memory behavior in this block of networking code

Situation - server having memory growth issues

cut out all the code except this bit, where a client is constantly
sending message and this just receives them, does nothing, and then
receives again.

I had stuck in a GC.Collect() and GC.WaitForFinalizers() call in the
code so I could more easily watch the gen2 heap size and see if it was
steady or not. But if I put it in one place, it would be steady, in
another it would grow!!?? (see comments in code below)

Whats up with that, and am I doing anything wrong with how I am using
async sockets here?
public void OnDataReceived(IAsyncResult asyn)
{
MsgState msgState=null;
try
{

msgState = (MsgState)asyn.AsyncState ;

int bytesReceived = 0 ;
bytesReceived = msgState.socket.EndReceive (asyn);
msgState.pos += bytesReceived;
//A result of 0 implies that the socket has died
if (bytesReceived == 0)
{
SocketClosed(msgState.socket);
return;
}

//comment this out to narrow down the problem
//msgState = processMessage(msgState);
msgState.reset(); //reset
position so the buffer won't grow

//if I put a GC.Collect() here, gen2 heap grows constantly
msgState.socket.BeginReceive
(msgState.dataBuffer,msgState.pos,msgState.expecte dSize-msgState.pos,SocketFlags.None,msgState.callBack,ms gState);
// but if I put the GC.Collect() here, the gen2 heap remains constant
as expected...
}

Jul 21 '05 #1
0 1197

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Michael | last post by:
In the below example, I beleive that the char array buffer should only occupy 40 bytes of the stack within the inner braces. However the compiler seems to use 40 bytes of the stack througout the...
9
by: Jon Davis | last post by:
I really don't like the speed bottleneck of SOAP. Is it possible to have shared memory, without using networking calls, within .NET? It seems like even though protected memory was a godsend for...
0
by: jack | last post by:
Situation - server having memory growth issues cut out all the code except this bit, where a client is constantly sending message and this just receives them, does nothing, and then receives...
10
by: weichaoliu | last post by:
I know that this problem is concerned to GCC. But I hope somebody here can tell me some detailed things about why. The version of g++ I'm using is: g++ (GCC) 3.4.4 (mingw special). The code is:...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
10
by: John Kraft | last post by:
Hello all, I'm experiencing some, imo, strange behavior with the StreamReader object I am using in the code below. Summary is that I am downloading a file from a website and saving it to disk...
171
by: Raman | last post by:
Hi All, Here is a small Code, int main(void) { char *p=(char *) malloc(100); strcpy(p,"Test1234567890"); p=p+10; free(p);
8
by: FBM | last post by:
Hi there, I am puzzled with the behavior of my code.. I am working on a networking stuff, and debugging with eclipse (GNU gdb 6.6-debian).. The problem I am experiencing is the following: ...
2
by: Andy Carlson | last post by:
I have a strange problem. I am trying to use a global variable, but I can't get the second routine to recognize changes to the globabl. I finally realize, that I was forking, so the global was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.