473,395 Members | 1,571 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,395 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 1198

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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.