help me with memry leak! C#

Started by
28 comments, last by JohnnyCode 11 years, 11 months ago
There are like 6 streams in there... Disposing one... sigh.

You need to learn. Just slapping together code until something kinda works is the worst kind of programming. Do some research, do some experimentation, extrapolate facts into knowledge.
Advertisement
Thanks.
[font=arial,helvetica,sans-serif]Everything except m_pStream and m_pClient is null. This is temporary release function, since I am tracking error, not finalizing code. What might couse memory leak after I read data from m_pStream by these 3 lines of code?[/font]
Nothing in the code you've shown (beyond not disposing of disposable resources of course). Assuming you take the data in the buffer and move it somewhere, that will increase your memory usage, but that's not a leak per se; just normal operating cost.
you can asssume that code is not leaking, unless I add these 3 instructions
[source]
byte[] buff = new byte[4000];
client.m_pRHandle = client.m_pStream.BeginRead(buff, 0, 4000, null, null);
int redbytes = client.m_pStream.EndRead(client.m_pRHandle);
[/source]

With these lines of code added it leaks.
I am so confused. Why possibly? I would be happy for any suggestion.
I'm still not sure why you think this is a leak and not just normal operation of the GC?

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

You are saying interesting thing apochpiq. Well it is like this.
If I do not use the 3 lines memory stays on 37mb with volatility 10mb, for all time, it does not move to higher values. But if I add the 3 lines, it behaves much more different. Memory keeps growing the way, more time, bigger minimal memory allocated and the volatility is like 10mb. In like 2 hours it is not droping. I have not run out of system mem yet, it will take me too long to achieve that, I will be right back giving you total result of the experiment. Right now for example, I started using delegate callback , memory cummulates from 40mb to 70mb, and when I do not use delegate it cummulates from 40mb to 120 mb. After this I assume I have allocations that are not free to OS and close the app. Using delegates My PC is exhousted with two requests, without delegates about 10 requests per second. But on my i54core I can handle 1000 requests, but trouble is I have 8GB ram there :).
what delegates?
the callback delegate for asynchronous calls. But I just tried that, I deffinitely will not use delegates. Ok I am hammering my server for 30 minnutes now and the memory , performing the three lines on connected clients then releasing them, got from 40mb over 30 minnutes to 140mb. I will continue but I believe I am leaking
memory is now 182mb I am leaking for sure.
Just post the code. C# code can only really leak memory in 2 ways:

  1. You're not disposing disposables.
  2. You're creating an object, adding a method from it to an event/delegate and then thinking it will be garbage collected.

Otherwise the memory will increase due to you using it. Anything else is user/measurement error.

This topic is closed to new replies.

Advertisement