Need help to understand Real-Time View

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.

Moderator: SciTech Software

Need help to understand Real-Time View

Postby Derik » Tue Jan 05, 2010 8:17 am

I'am using Visual Studio C++ with .Net and MemProfiler 3.5.

I'am using your tool because I am thinking to have a leak in my application. To find out where may be the problem I switching down all funtions and test each only by its self.
This code I test in the first (a simple timer who is checking the process list each second):
Code: Select all
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {

          Process ^prozesse=gcnew Process();
          for each(Process ^element in prozesse->GetProcesses())
             listBox1->Items->Add(element->ProcessName);
          delete prozesse;
       }


When I now start the programm and take a view on Real-time I see that Total instances are growining and growing and growing. The same for Gen 0 to Gen 2.

I'am not sure, is the a problem and if yes what is wrong with the code?

All the best,
Derik
Derik
 
Posts: 3
Joined: Tue Jan 05, 2010 7:37 am

Re: Need help to understand Real-Time View

Postby Derik » Tue Jan 05, 2010 7:18 pm

One Information was left in my thread. The ListBox would be ceared in an other thread syncron to this timer.
If you try to test please us this to:
Code: Select all
listBox1->Items->Clear();
Derik
 
Posts: 3
Joined: Tue Jan 05, 2010 7:37 am

Re: Need help to understand Real-Time View

Postby Andreas Suurkuusk » Wed Jan 06, 2010 8:20 pm

Your example code creates several new instances in each timer tick, so it's expected that the number of GCs increases continously. However, if the ListBox is cleared correctly (as you mention in your second post), then the garbage collector should be able to collect the process name strings that were created when adding them to the ListBox. After the GC, I wouuld expect the number of Total instances to decrease.

Which classes have an increasing amount of Total instances? What happens if you collect a heap snapshot? Does the total instances value decrease, or does the live instances value increase?
Best regards,

Andreas Suurkuusk
SciTech Software AB
Andreas Suurkuusk
 
Posts: 995
Joined: Wed Mar 02, 2005 7:53 pm
Location: Sweden

Re: Need help to understand Real-Time View

Postby Derik » Thu Jan 07, 2010 9:32 am

Hello Andreas,

thaks a lot for your help.
I the case below I have only do a test with the process claas. I have do this because i did have a real big program where this is included to check for other processes. If some other special programs are finished my application needs to be finished too.
As I have described before I think there is a leak because if my program is working some weeks around the clock it can be that after this long time other programs did have real problems to work correctly. It can be to that the other programs are stopping they work with an error.

To figure out what cause the leak problem in my application I do a lot of tests like this with your profiler.

I have now changed my test code a bit. The processes would be checked now with a button.
Code: Select all
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
            
             listBox1->Items->Clear();
            
             Boolean endApplication=false;

             Process ^prozesse=gcnew Process();
             array<Process^>^runningProcesses=prozesse->GetProcesses();
            
             /*for each(Process ^element in runningProcesses)
                if(element->ProcessName=="xxx")
                   endApplication=true;   */   

             for each(Process ^element in prozesse->GetProcesses()){
                listBox1->Items->Add(element->ProcessName);
                delete element;
             }            
            
             delete prozesse;

             if(endApplication==true)
                this->Close();
          }


With each click on the button the total instances an bytes are growing only and do not fall back. You can see it in the added picture realtime.
RealTime.jpg
Real Time view
RealTime.jpg (80.64 KiB) Viewed 4476 times


You ask for the snapshot and whats happend. Plase take a look on the next picture.
You see there mainly System.Diagnostic with new instances.
Thr claas process is displayed as undisposed but gc collected too.
TypesResourses.jpg
TypesResoures
TypesResourses.jpg (160.23 KiB) Viewed 4476 times


Can this be normal? Isn't this a leak?
Derik
 
Posts: 3
Joined: Tue Jan 05, 2010 7:37 am

Re: Need help to understand Real-Time View

Postby Andreas Suurkuusk » Thu Jan 07, 2010 1:53 pm

The screenshots do indicate a possible memory leak, but using your example code I have not been able to reproduce the error.

Are you actually seeing this problem in a simple Windows forms application using the button handler in your example? One thing I noted in your example is that you retrieve the processes array twice, but you only dispose the Process instances the second time it's retrieved. This will cause instances to become undisposed and they will require finalization.

Have you investigated the root paths of the Process instances? The root paths will tell you why the instances have not been collected. If you need help parsing the root paths, copy them into a reply to this post.
Best regards,

Andreas Suurkuusk
SciTech Software AB
Andreas Suurkuusk
 
Posts: 995
Joined: Wed Mar 02, 2005 7:53 pm
Location: Sweden


Return to Using .NET Memory Profiler

Who is online

Users browsing this forum: Exabot [Bot] and 7 guests

SciTech Software logo

© Copyright 2001-2016. SciTech Software AB
All rights reserved.


SciTech Software AB
Kartvägen 21
SE-175 46 Järfälla
Sweden


E-mail: mail@scitech.se

Telephone: +46-706868081

cron