High Memory and CPU Usage When Debugging Lots of Dynamic Types

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.


Action

Debugging managed code that contains a lot of dynamically created types.


Result

High memory usage accompanied by high cpu usage.


Cause

High Memory Usage:
The Visual Studio debugger makes a copy of meta-data every time a managed dynamic type is created, even when it already has a previous copy of the same type cached.  This is because there may still be outstanding references to the old copy.  So, when re-creating dynamic types, not only does the debugger make a copy of meta-data for itself to use, it may also create what amouts to a duplicate copy.

High CPU:
This particular pattern of memory usage can also lead to fragmented native heaps in the process.  As the debugging activity progresses, native heaps can become more and more fragmented, causing high cpu usage as it becomes more and more difficult to free continguous space.


Resolution

This behavior is considered by design.


More Information

The only known workaround is to detach the debugger periodically and re-attach.  When the debugger is detached, the copies of metadata are freed.

Othewise, be sure you are caching dynamic types such that you don’t re-create them, resulting in multiple copies of metadata for the same type.

Also, try to limit the number of dynamic types used; try to consolidate functionality in as few dynamic types as reasonably possible.


DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.



APPLIES TO
Microsoft Visual Studio .NET 2002 Professional Edition
Microsoft Visual Studio .NET 2003 Professional Edition
Microsoft Visual Studio 2005 Professional Edition
Microsoft Visual Studio 2008 Professional Edition

——————————————–

Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
Microsoft Corporation. All rights reserved. Terms of Use | Trademarks


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image