|
Also, keep in mind that if you're looking at Task Manager to tell you how much memory your app is using, it's lying to you. You're seeing how much memory is RESERVED by the .NET CLR for your app, NOT how much your app is actually using. The .NET CLR keeps a managed memory pool that your objects are allocated from. If you free an object, the memory goes back into the pool for future use. It is NOT returned to Windows! The .NET CLR will return memory to Windows if Windows wants it back. Otherwise, it'll keep the memory in the managed pool.
|
|
|
|
|
Erhm, actually... that WAS the tool I was using to monitor the memory consumption. I'll try some performance counters, maybe I can find a more accurate result there.
Thanks for sharing your meaning...
|
|
|
|
|
I would probably agree here. The objects you have are probably referenced within the main application either through events (the little devils) or main variables. Setting these variables to null rather than the reference to the object may allow the garbage collector to work its magic, or you can try calling it directly to see if its just being lazy.
Event disposal
How to: Subscribe to and Unsubscribe from Events
Just noticed that Covean has posted about the GC that should be useful.
modified on Thursday, January 21, 2010 5:50 AM
|
|
|
|
|
Disposing an item does not mean that the GC collects it immediately or even frees memory.
The GC tries to keep memory allocation fast/flexible and if your app constantly allocates large objects
for medium/long-lifetime and disposes it, the GC could decide not to free its memory because it awaits
a new object allocation soon.
I would try to force the GC to collect all generations in idle-state.
GC.Collect();
GC.WaitForPendingFinalizers();
If your memory consumption now falls down in idle-state, you know that the GC causes this behaviour
and you should decide if its better to let the GC do it on its own or to force it.
If your memory consumption doesn't fall down then you really should look if you don't use some
unmanaged resources.
Greetings
Covean
|
|
|
|
|
Before you spend a lot of time, just perform a simple experiment:
- run the app, don't let it exit
- watch the working set on TaskManager
- minimize the main form
- restore the main form
- watch the working set again on TaskManager
if it got way down, then nothing is wrong; the memory IS available for use by other processes, and minimizing makes Windows reclaim memory from an app. The effect will be most noticeable on recent Windows versions (Vista, 7).
if not, you are holding on on something, or have a real leak.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Wouldn't it be better if he uses some kind of memory profiler? They would, IMO, give specific results.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
I haven't used memory profilers yet, I include what I deem necessary in my own code. So I can't advice about them as I don't know how intelligible their output would be for a novice.
And that is why I prefer a simple experiment over installing yet another tool.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
I haven't used a profiler as well. This morning I downloaded one to find the cause of my problem. The profiler however gives me loads and loads of information which I don't know how to 'read'. I tried your tip and yes, the amount of used memory dramaticly decreases when minimized. This is however when I use my test application which is a windows forms app. The actual app. is a Windows Service and since that has no GUI I cannot minimize it Thanks for the tip!
|
|
|
|
|
yes, "loads of information a novice won't understand" often is the outcome of a tool, even a good one.
your app (as a WinForms app) going down to acceptable and repeatable levels should tell you all is well.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
<br />
string from, to;<br />
from = frm.dtp1();<br />
to = frm.dtp2();<br />
sql = "select convert(varchar(10),tim,120) as dates,sum(mone) as totals,count(ID) as totalman from pat where (datepart(mm,tim) like '__' or datepart(mm,tim) like '_') and convert(varchar(10),tim,120) between '" + from + "' and '" + to + "' group by convert(varchar(10),tim,120)";
like that,i use this SQL do my report,then write Sum ({DataTable1.totalman}) and Sum ({DataTable1.totals}) on my crystal report.then run my project
the totalman should be 62,but it shows on report is 62.00,why?i think it should't like that?
|
|
|
|
|
Hi guyzz.. i have a doubt may be i have a query in C# coding and the query returns a string... Now i need to perform a check using if statement, my check is that if the query returns any string value then grant permission else access denied... Now my doubt is how do i specify "return any string value" in the if condition... plz advice...
If(query == ?????)
{
permission granted
}
|
|
|
|
|
Either check if (query.Length > 0) or if (query != string.Empty) . If your query variable can be null then you can check if(query != null) . Good luck!
<added>
so your statement should read:
if (query != null)
{
if (query.Length > 0)
}
|
|
|
|
|
Thanx.. its actually very silly doubt... the logic dint strike me as im a new comer in programming... Thanx alot..
regards,
tash
|
|
|
|
|
to check if a string is null or empty, usually if(!String.IsNullOrEmpty(value)) should be used. This checks for both empty and null strings.
|
|
|
|
|
Thanx buddy...
Regards,
Tash
|
|
|
|
|
welcome!!
|
|
|
|
|
How come is still don't remember this String method..?
|
|
|
|
|
Happens buddy!!! All in a day's work.
|
|
|
|
|
if (!string.IsNullOrEmpty(query))
{
}
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi Friends,
Is possible to run 500 threads per second using c#?
Please help me
Thanks in advance
|
|
|
|
|
C# would not be the limiting factor.
Windows could probably cope; a server version would for sure.
But I haven't encountered any application yet where it would make sense to have that many threads in a single process. It would be a huge waste of cycles (thread switches are expensive), bytes (each thread has its context, where the stack is the biggest chunck), and time (your cache efficiency goes down as the fixed size caches are used by more threads now).
Here is my rule of thumb in multi-threading: For most apps, it does not pay to have similar code in more than 1*N to 2*N threads where N is the number of processors.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Thank you your reply.
Is there any example to use multi threading (Asynchornous and thread pool) in C# window service application?
|
|
|
|
|
Does this[^] help?
Now...bring me that horizon. And really bad eggs...Drink up me hearties, YO HO!
|
|
|
|
|
|
Luc Pattyn wrote: have similar code in more than 1*N to 2*N threads
My rule of thumb is 1.5*N
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Harvey Saayman wrote: 1.5*N
you may run into trouble on an AMD triple core...
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|