Monday, August 27, 2012

Out-Of-Memory error and Visual Studio crashes

As part of assignment, I was working on a project, which is having 137 projects Windows Form in a solution. Whenever I was building my solution, I was getting Out-Of-Memory error and due to this my Visual Studio use to get crash. Then the only solution left with me was to restart my Visual Studio L. Earlier I as facing this issue once a while, but from last week, it is occurring frequently. Hope you can imagine, how painful it is restart the Visual Studio every now-and-then, especially when your solution contains such a huge number of projects. My error was something like this: “The "ResolveManifestFiles" task failed unexpectedly.System.OutOfMemoryException: Insufficient memory to continue the execution of the program.” 

The only thing, which was coming into my mind, was that it is due to Visual Studio’s memory limits. I also tried to minimize Visual Studio, but no luck :(.
After consulting with few people, I got an idea to breakup my solution into multiple solutions. But again, it was not the best solution for me because my project was already on the last stage (about to over) and it was not the correct time to take this much big risk. So, I dropped this suggestion also.  

After hitting my head for 4-5 days, I reached to some conclusion. One of the reasons was Heap fragmentation, due to which, my Virtual Memory was keep raising and ultimately it was affecting my GC. But this reason was also not 100% correct. Because Virtual Memory will rise, only when I’ll run my application. But in my case, I was getting error during build itself. So, again no luck :(

While doing analysis on the same, I thought, let’s open manifest file and check once. And luckily I got the clue. On opening manifest file, I found that there are lot of hash values which are nothing but my image files. In my project I was using approx 150 image files. According to my project requirement, we were not supposed to deploy those image files. Then what those files were doing there, why they are part of my manifest?  Now a very BIG question was, how those image files became part of my manifest?

This happened because Visual Studio, by default sets image’s ‘Build Action’ property to ‘Content’. As soon as I changed this property to ‘None’, my error goes off. This one small property worked like a charm for me :)

By setting ‘Build Action’ property to ‘None’, I was able to reduce the size of manifest file to approx 0.9GB.

I shared this as a tip, so that you need not to spend 5-6 days, to analyze the issue :)

1 comment:

  1. I had the same issue.
    I'll go with this next time...