Stylecop - Excess memory usage

Apr 12, 2011 at 9:01 AM

Hi,

We're currently using Stylecop for our C# application (via StyleCopCmd on the build server). However, it has started to be come unusable due to OutofMemory errors. After some investigation, it seems StyleCopCmd is consuming over 1Gb of memory on our larger projects.

I thought this may have been the StyleCopCmd's fault, so I've tried running with the MSBUILD integration, but I still have the same result. Is this type of memory use expected, or is there any setting where we can control the memory usage? VS uses enough memory as it is, without adding the Stylecop checks to this as well. If it continues to consume this amount of memory, we won't be using it - which is unfortunate. :-(

Our environment is VS2005, WinXP, Stylecop v4.3 (v4.4 FTW also exhibits the same behavior).

Cheers,

Daniel B.

Coordinator
Apr 12, 2011 at 9:53 AM
Edited Aug 23, 2011 at 9:24 AM
Hi Daniel.
Can you retest with the latest 4.5 please? There are over 120 bug fixes in 4.5 already so it may be fine.
If not fixed I'll investigate with you until it is. I can't fix 4.3 but whatever is happening can be sorted in 4.5 if not already done.
Apr 12, 2011 at 11:43 AM
andyr wrote:
Hi Daniel.
Can you retest with the latest 4.5 please? There are over 120 bug fixes in 4.5 already so it may be fine.
If not fixed I'll investigate with you until it is. I can't fix 4.3 but whatever is happening can be sorted in 4.5 if not already done.
On 12 Apr 2011, at 09:01, "djcbecroft" <notifications@codeplex.com> wrote:

From: djcbecroft

Hi,

We're currently using Stylecop for our C# application (via StyleCopCmd on the build server). However, it has started to be come unusable due to OutofMemory errors. After some investigation, it seems StyleCopCmd is consuming over 1Gb of memory on our larger projects.

I thought this may have been the StyleCopCmd's fault, so I've tried running with the MSBUILD integration, but I still have the same result. Is this type of memory use expected, or is there any setting where we can control the memory usage? VS uses enough memory as it is, without adding the Stylecop checks to this as well. If it continues to consume this amount of memory, we won't be using it - which is unfortunate. :-(

Our environment is VS2005, WinXP, Stylecop v4.3 (v4.4 FTW also exhibits the same behavior).

Cheers,

Daniel B.

Hi Andy,

I downloaded 4.5 beta, and it still uses the same amount of memory. It raised the "no new lines at end of file" warnings, so I'm pretty sure the right one was being executed.

Cheers,

Daniel B.

Coordinator
Apr 12, 2011 at 4:23 PM

Hi Daniel,

This is going to be tricky to investigate. Exactly how big is the solution? You're trying StyleCop 4.5 beta from the msbuild task right? I'm going to need to try and repro it here.

Apr 12, 2011 at 10:16 PM

Hi Andy,

The .sln file is 7kb, the .csproj file that I've added the task to is about 750Kb. It includes (approximately) 3200 *.cs files (with approx 1500 *.designer.cs files).

I added the following line to the .csproj file, and executed the build via MSBUILD.exe (it's being executed from within an ant build script, although I doubt that is the cause).

  <Import Project="$(ProgramFiles)\MSBuild\StyleCop\v4.5\StyleCop.targets" />

The only way I know that v4.5 was selected were the new warnings that appeared. Are there any tools I can use to attached to the running msbuild.exe to see what's happening?

Cheers,

Daniel B.

Apr 21, 2011 at 12:19 AM

Hi Andy,

Was there any further information that you required for this? Or is there anything further I can do here to debug this problem?

Cheers,

Daniel B.

Coordinator
Apr 21, 2011 at 9:07 AM

I created a solution of 5000 cs files and 2500 designer files. I see no memory leaks at all. Now I am testing this with VS2010. I'm not sure where to go on this next. 

Apr 21, 2011 at 9:46 AM
andyr wrote:

I created a solution of 5000 cs files and 2500 designer files. I see no memory leaks at all. Now I am testing this with VS2010. I'm not sure where to go on this next. 

Okay, I'll see if I can get some more information (attach procmon.exe or something similar). My tests have been compiling a VS2005 project through MSBUILD (3.5) on the- command-line, not through VS itself (if that makes a difference).

Cheers,

Daniel B.

Apr 24, 2011 at 2:37 AM

Okay, I've run the ANTS Memory Profiler against the original StyleCopCmd version (unfortunately not able to run against v4.5 at this point).

It seems the bulk of the memory being used is due to instances of the Microsoft.Stylecop.CodePoint class (all referenced via instances of CodeLocation). The snapshot I looked at was early on in the process, and there was about 2.9 million CodePoint objects around already. According to the Retention Graph, the Microsoft.Stylecop.CSharp.CsParser object is holding references (somewhere) that prevent everything being cleaned up by the GC.

I'll try and get ANTS run against 4.5 so that the references and class names are a bit more up to date, but hopefully that might help out a bit.

Cheers,

Daniel B.

Coordinator
Apr 24, 2011 at 2:46 AM
Ok. You ran that on 4.5.
I'll try and follow that object and see whats happening.

A.


On 24 Apr 2011, at 02:38, "djcbecroft" <notifications@codeplex.com> wrote:

From: djcbecroft

Okay, I've run the ANTS Memory Profiler against the original StyleCopCmd version (unfortunately not able to run against v4.5 at this point).

It seems the bulk of the memory being used is due to instances of the Microsoft.Stylecop.CodePoint class (all referenced via instances of CodeLocation). The snapshot I looked at was early on in the process, and there was about 2.9 million CodePoint objects around already. According to the Retention Graph, the Microsoft.Stylecop.CSharp.CsParser object is holding references (somewhere) that prevent everything being cleaned up by the GC.

I'll try and get ANTS run against 4.5 so that the references and class names are a bit more up to date, but hopefully that might help out a bit.

Cheers,

Daniel B.