Debugging Out of Memory Exceptions in Visual Studio .NET

Paint QR Code ISO/IEC18004 in Visual Studio .NET Debugging Out of Memory Exceptions
Debugging Out of Memory Exceptions
QR Code ISO/IEC18004 Printer In .NET
Using Barcode creator for VS .NET Control to generate, create Denso QR Bar Code image in VS .NET applications.
illustrates how memory can be exhausted in the managed world and does not cover the various ways in which resources can be leaked in native code when invoked via the interoperability services layer In 7, Interoperability, we will look at an example of a native resource leak caused by improper invocations from managed code The application we will use to illustrate the problem is shown in Listing 5-9 Listing 5-9 Example of an application that causes an eventual OutOfMemoryException
Read QR-Code In Visual Studio .NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in VS .NET applications.
using System; using SystemIO; using SystemXmlSerialization; namespace AdvancedNETDebugging5 { public class Person { private string name; private string social; private int age; public string Name { get { return name; } set { thisname=value;} } public string SocialSecurity { get { return social; } set { thissocial= value; } } public int Age { get { return age; } set { thisage = value; } } public Person() {} public Person(string name, string ss, int age)
Bar Code Drawer In Visual Studio .NET
Using Barcode drawer for .NET framework Control to generate, create bar code image in .NET applications.
5 MANAGED HEAP AND GARBAGE COLLECTION
Bar Code Decoder In VS .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
(continues)
Making QR Code In C#.NET
Using Barcode creation for VS .NET Control to generate, create QR image in Visual Studio .NET applications.
5
Generating QR Code In VS .NET
Using Barcode maker for ASP.NET Control to generate, create Quick Response Code image in ASP.NET applications.
Managed Heap and Garbage Collection
QR Code Maker In Visual Basic .NET
Using Barcode creator for .NET framework Control to generate, create QR image in VS .NET applications.
Listing 5-9 Example of an application that causes an eventual
Encode Barcode In .NET
Using Barcode creator for .NET framework Control to generate, create bar code image in .NET applications.
OutOfMemoryException (continued)
Print Data Matrix 2d Barcode In .NET Framework
Using Barcode encoder for .NET Control to generate, create Data Matrix ECC200 image in VS .NET applications.
{ thisname = name; thissocial = ss; thisage = age; } } class OOM { static void Main(string[] args) { OOM o = new OOM(); oRun(); } public void Run() { XmlRootAttribute root = new XmlRootAttribute(); rootElementName = "MyPersonRoot"; rootNamespace = "http://wwwcontosocom"; rootIsNullable = true; while (true) { Person p = new Person(); pName = "Mario Hewardt"; pSocialSecurity = "xxx-xx-xxxx"; pAge = 99; XmlSerializer ser = new XmlSerializer(typeof(Person), root); Stream s = new FileStream("c:\\sertxt", FileModeCreate); serSerialize(s, p); sClose(); } } } }
Code39 Generator In .NET
Using Barcode generation for VS .NET Control to generate, create Code39 image in .NET framework applications.
The source code and binary for Listing 5-9 can be found in the following folders:
Painting Barcode In .NET
Using Barcode encoder for VS .NET Control to generate, create barcode image in Visual Studio .NET applications.
Source code: C:\ADND\5\OOM Binary: C:\ADNDBin\05OOMexe
Encode UPC Shipping Container Symbol ITF-14 In Visual Studio .NET
Using Barcode generator for Visual Studio .NET Control to generate, create DUN - 14 image in VS .NET applications.
Debugging Out of Memory Exceptions
Creating Bar Code In C#.NET
Using Barcode creation for .NET framework Control to generate, create bar code image in .NET framework applications.
The application is pretty straightforward and consists of a Person class and an OOM class The OOM class contains a Run method that sits in a tight loop creating instances of the Person class and serializes the instance into XML stored in a file on the local drive When we run this application, we would like to monitor the memory consumption to see if it steadily increases over time, which could eventually lead to an OutOfMemoryException being thrown What tools do we have at our disposal to monitor the memory consumption of a process We have several options The most basic option is to simply use task manager (shortcut SHIFTCTRL-ESC) Task manager can display per-process memory information such as the working set, commit size, and paged/nonpaged pool By default, only the Memory (Private Working Set) is enabled To enable other process information, the Select Columns menu choice on the View menu can be used The Windows Task Manager has several different tabs, and the tab of most interest when looking at per-process details is the Processes tab The Processes tab shows a number of rows where each row represents a running process Each of the columns in turn shows a specific piece of information about the process Figure 5-13 shows an example of Windows Task Manager with a number of different memory details enabled in the Processes tab
Generating Bar Code In VB.NET
Using Barcode drawer for Visual Studio .NET Control to generate, create barcode image in .NET applications.
5 MANAGED HEAP AND GARBAGE COLLECTION
ECC200 Reader In VS .NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
Figure 5-13 Example of Windows Task Manager Processes tab
Recognize EAN-13 In .NET Framework
Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
5
Creating GS1 - 12 In Java
Using Barcode generation for Java Control to generate, create UPCA image in Java applications.
Managed Heap and Garbage Collection
Bar Code Printer In .NET
Using Barcode printer for ASP.NET Control to generate, create barcode image in ASP.NET applications.
In Figure 5-13, we can see, for example, that explorerexe s working set size is 37,420K Before we can move forward and effectively utilize Windows Task Manager for memory-related investigations, we have to have a clear understanding of what each of the possible memory-related columns means Table 5-2 details the most commonly used columns and their descriptions
Creating EAN13 In Visual Studio .NET
Using Barcode generator for ASP.NET Control to generate, create EAN-13 Supplement 5 image in ASP.NET applications.
PRE-WINDOWS VISTA TASK MANAGER Some much-needed changes were made in Windows Vista and later versions to better capture the memory-related process information Prior to Windows Vista, Windows Task Manager had a column named VM size, which, contrary to popular belief, indicated the amount of private bytes a process was consuming Similarly, the Mem Usage column corresponds to the working set (including shared memory) of the process Finally, a feature we will utilize in 8, Postmortem Debugging, is the capability to create dump files simply by right-clicking on the process and choosing the Create Dump File item
Code 3/9 Creator In VS .NET
Using Barcode creation for ASP.NET Control to generate, create Code39 image in ASP.NET applications.
Let s run 05OOMexe and watch the Memory Working Set, Memory Private Working Set, and Memory Commit Size columns Table 5-3 shows the results taken at periodic (approximately 60-second) intervals Table 5-2 Windows Task Manager Memory-Related Columns