---
title: ".NET Continuous Profiler: Memory usage"
description: "Datadog's .NET continuous profiler measures memory in three ways."
url: "https://swe.quest/articles/net-continuous-profiler-memory-usage-51d84deba820efcb"
canonical: "https://www.datadoghq.com/blog/engineering/dotnet-continuous-profiler-part-4/"
source: "Datadog Engineering"
published: "2024-05-20"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 9
tags: ["dotnet","memory-management","observability","performance","runtimes"]
---

# .NET Continuous Profiler: Memory usage

A post on [Datadog Engineering](https://swe.quest/sources/datadog.md), published 2024-05-20, 9 min read, Deep dive. Original: [https://www.datadoghq.com/blog/engineering/dotnet-continuous-profiler-part-4/](https://www.datadoghq.com/blog/engineering/dotnet-continuous-profiler-part-4/)

## Summary

Datadog's .NET continuous profiler measures memory in three ways. It pulls per-thread CPU time for the .NET Server GC/BGC threads (available since .NET 5) to show garbage collector cost. It samples allocations via the CLR's AllocationTick event, fired every 100 KB per SOH/LOH/POH, and walks the stack on the current thread. It tracks surviving objects with weak handles through a new ICorProfilerInfo13 API added in .NET 7, patching the MethodTable slot with the ClassID so a handle can be created before the object exists. Validation showed the fixed 100 KB threshold produces unrepresentative samples, so values are not upscaled until the CLR adopts Poisson-distributed sampling thresholds like the Go and Java profilers.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [.NET](https://swe.quest/tags/dotnet.md) (Languages)
- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)

## Prerequisites

- .NET garbage collector generations ([easy posts on .NET](https://swe.quest/tags/dotnet.md?difficulty=easy))
- .NET profiling API (ICorProfiler) ([easy posts on .NET](https://swe.quest/tags/dotnet.md?difficulty=easy))
- CLR event tracing ([easy posts on Observability](https://swe.quest/tags/observability.md?difficulty=easy))
- statistical sampling

## Keywords

Datadog, CLR, ICorProfilerInfo13, AllocationTick, GCHandle, EventPipe

## Related posts

- [.NET Continuous Profiler: CPU and wall time profiling](https://swe.quest/articles/net-continuous-profiler-cpu-and-wall-time-profiling-5dcdacf43942cb04.md): Datadog Engineering · 2024-02-13 · Hard · 10 min read · .NET, Performance engineering, Runtimes & VMs, Observability, Linux
  Datadog's .NET continuous profiler samples managed threads every 10 ms instead of relying on ETW, perf or enter/leave hooks, which cost too much for 24/7 production use.
- [.NET Continuous Profiler: Under the hood](https://swe.quest/articles/net-continuous-profiler-under-the-hood-46b61cbffdef64a4.md): Datadog Engineering · 2024-01-09 · Hard · 9 min read · .NET, Performance engineering, Observability, Runtimes & VMs
  Datadog's .NET continuous profiler runs in-process as native C++ and Rust code loaded through the CLR's ICorProfilerCallback interface.
- [.NET Continuous Profiler: Exception and lock contention](https://swe.quest/articles/net-continuous-profiler-exception-and-lock-contention-93247ad1a6e667eb.md): Datadog Engineering · 2024-04-04 · Hard · 8 min read · .NET, Performance engineering, Observability, Concurrency, Runtimes & VMs
  Datadog's .NET continuous profiler captures thrown exceptions through ICorProfilerCallback::ExceptionThrown and reads each exception's \_message field by resolving System.Exception's ClassID from CoreLib metadata and computing the field offset with GetClassLayout.
- [How we wrote a Python profiler](https://swe.quest/articles/how-we-wrote-a-python-profiler-397d52e3f1db71ec.md): Datadog Engineering · 2020-10-07 · Medium · 7 min read · Python, Performance engineering, Observability
  Datadog built an always-on statistical profiler for Python because deterministic profilers like cProfile can add 2-3x overhead, too much for production.
- [Unbiased Java CPU profiling with JFR in JDK 25](https://swe.quest/articles/unbiased-java-cpu-profiling-with-jfr-in-jdk-25-9bdec8ca98b4801c.md): Datadog Engineering · 2026-07-22 · Medium · 10 min read · Java & JVM, Performance engineering, Observability, Runtimes & VMs
  JDK 25 adds an experimental JFR CPU-time sampling event (CPUTimeSample) that gives unbiased CPU profiles without relying on the unsupported HotSpot AsyncGetCallTrace API.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
