I have a solution with two applications. One is Windows Service project, another one is launcher (installs and starts the windows service). I want to attach memory profiler to the installed windows service to collect information about memory usage and object sizes to investigate the OutOfMemory exception.
Here is the approach I used.
First I ran the "VSPerfCLREnv.cmd /samplegclife". This should init the profiling environment variables to enable memory profiling.
Then I start my launcher, which launches the service.
Finally VS 2010 -> Analyze -> Profiler -> attach (to the windows service).
But when the profiling is stopped I cannot see any information about object sizes or memory usage.
Am I doing something wrong?
I found out.
To attach the profiler to .net process to collect memory data you should follow these steps:
1. Initialize the profiling environment variables:
VSPerfClrEnv /globalsamplegc
Reboot PC.
2. Start profiling session:
VSPerfCmd /start:"sample" /output:"C:\log.vsp" /crosssession
3. Attach the profiler to the process:
VSPerfCmd /attach:[PID]
4.To stop profiling:
VSPerfCmd /detach
VSPerfCmd /shutdown
For more information refer to this.
Actually it meant that the memory of object has been corrupted while storing the data...To Exclude this you have to invoke garbage collector like GC.collect() and free's the unused memory by assigning null...For Example:string sTest="Tested";string sAssign=sTest;sTest=null; To View total memory of an object use GC.GetTotalMemory(false);