Help and Support

High Memory and CPU Usage When Debugging Lots of Dynamic Types

Article ID:948032
Last Review:January 22, 2008
Revision:1.1
Source: Microsoft Support

Back to the top

RAPID PUBLISHING

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.

Back to the top

Action

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

Back to the top

Result

High memory usage accompanied by high cpu usage.

Back to the top

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.

Back to the top

Resolution

This behavior is considered by design. 

Back to the top

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.

Back to the top

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.

Back to the top


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

Back to the top

Keywords: 
kbnomt kbrapidpub KB948032

Back to the top

Other Support Options

  • Contact Microsoft
    Phone Numbers, Support Options and Pricing, Online Help, and more.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.