Skip to Main Content
Visual Studio Hacks
book

Visual Studio Hacks

by James Avery
March 2005
Intermediate to advanced content levelIntermediate to advanced
304 pages
19h 23m
English
O'Reilly Media, Inc.
Content preview from Visual Studio Hacks
266
|
Chapter 7, Help and Research
#67 Profile Heap Allocations
HACK
HACK
#67
Profile Heap Allocations Hack #67
Use the Allocation Profiler to research how your objects are being handled on
the heap.
This hack is an introduction to the Allocation Profiler tool available at www.
gotdotnet.com. The Allocation Profiler tool allows developers to analyze allo-
cations on the garbage collection heap. The Allocation Profiler answers
questions about the object(s) in your application such as: How many times
was my object created in memory? At what point in execution time was my
object allocated? How long was my object alive?
Let’s write a very basic C# application to see the Allocation Profiler in its
simplest form. The application will run a loop and create 10,000 instances
of our simple class.
Here is the code for AP_example1.exe:
// main.cs
using System;
namespace AP_example1
{
/// <summary>
/// Summary description for main.
/// </summary>
// basic class that creates a string object
public class AP_example_class
{
string s = String.Empty;
}
public class AP_example1
{
public static void Main( )
{
// create 10,000 instance of our class
for(int x=0;x<10000;x++)
{
AP_example_class aec = new AP_example_class( );
}
}
}
}
After compiling AP_example1, open AllocationProfiler.exe, which is shown
in Figure 7-39.
Profile Heap ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft Visual Studio 2015 Unleashed, Third Edition

Microsoft Visual Studio 2015 Unleashed, Third Edition

Mike Snell, Lars Powers
.Net Framework Essentials

.Net Framework Essentials

Thuan L. Thai, Hoang Lam
C# 5.0 Unleashed

C# 5.0 Unleashed

Bart De Smet
Programming .NET Security

Programming .NET Security

Adam Freeman, Allen Jones

Publisher Resources

ISBN: 0596008473Errata Page