.NETGURU
PerformanceCounter Mem Leak
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.performance.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

poor beggar
hello,

after starting a performance counter everything works fine, but every time I get the value of the counter I've a mem leak of 4K, what can I do against it ??

getting vallue : perfmoncounter.nextvalue

I' ve the problem with every counter I monitor! what to do against it ??

--
thanks for your attention,

poor_beggar

Click here to reveal e-mail address
Reply to this message...
 
    
Jerry Pisk
Upgrade to Windows 2003. PerformanceCounter leaks resources (system handles)
under Windows 2000 (and possibly others).

Jerry

"poor_beggar" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
poor beggar
Are You sure that that is the reason? so there is nothing I can do about it ??

So if my progrma runs on a Win 2003 PC I'll not have that problem, even when I take counters from a remote machine ?? or will I leak mem on the remote machine ?
--
thanks for your attention,

poor_beggar

Click here to reveal e-mail address

"Jerry Pisk" wrote:

[Original message clipped]

Reply to this message...
 
    
Jerry Pisk
No, I'm not sure that you're seeing the same problem. But look at the number
of handles used by your app, you should see that go up a lot, by 7 every
time you request a performance counter sample. Now there might be some
memory not being released as well, I haven't looked at my memory usage when
I was investigating this.

And as far as I could tell the problem is in the system library, so using
Win2k3 server to read remote counters should be ok. Give it a try.

Jerry

"poor_beggar" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Ryan Byington (VIP)
I tried this out and I do not think we are leaking bytes. I think that on
every iteration the GC does not free up the memory used by NextValue. I
wrote the following sample. With the GC.Collect() and
GC.WaitForPendingFinalizers() commented out the memory usage goes up every
iteration. However with these enabled the memory usage stay pretty
constant. The GC does not free up resources immediately after they go out
of scope and these method on the GC class will force the GC to run and free
up all resources. However I would not recomend calling them explicitly I
would just let the GC do it's thing.

using System;
using System.Diagnostics;

public class Test
{
    public static void Main()
    {
        PerformanceCounter pc = new PerformanceCounter("Processor", "% Processor
Time", "_Total");

        for(int i=0; i<1000; ++i) {
            Console.WriteLine(pc.NextValue());
            
            GC.Collect();
            GC.WaitForPendingFinalizers();
            System.Threading.Thread.Sleep(1000);
        }
    }
}

Ryan Byington [MS]

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

--------------------
[Original message clipped]

<Click here to reveal e-mail address>
[Original message clipped]

.phx.gbl
>Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.performance:8255
[Original message clipped]

Reply to this message...
 
 
System.Console
System.Diagnostics.PerformanceCounter
System.GC
System.Threading.Thread




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification