Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to Find and Fix Memory Leaks in .NET Projects

Memory leaks in .NET applications can be confusing. After all, .NET has a Garbage Collector (GC) that automatically removes objects that are no longer needed. So developers often ask: “If .NET has garbage collection, how can a memory leak happen?” The answer is that the Garbage Collector can only collect objects that are no longer reachable . If an object is still referenced somewhere in your…

Memory leaks can occur in .NET applications even though the language includes garbage collection. Despite having a GC that automatically frees memory from unreachable objects, a memory leak can still manifest if objects remain reachable due to lingering references. This article outlines a step-by-step approach to identifying and resolving memory leaks in .NET projects using tools like dotnet-counters, dotnet-dump, and dotnet-gcdump.

Memory leaks in .NET typically involve objects that are no longer logically required but still referenced somewhere in the application, preventing garbage collection and leading to increased memory usage. For instance, consider this code snippet:

```csharp

public class CustomerService {

private static readonly List<Customer> _customers = new ();

public void AddCustomer(Customer customer) {

_customers.Add(customer);

}

}

```

If customers are continuously added to the static list without removal, the memory usage will continue to grow as the GC cannot reclaim those objects because they are still reachable via references.

To investigate potential memory leaks, follow these six steps:

1. Confirm the Presence of a Memory Leak

- High memory usage doesn't automatically indicate a leak.

- Monitor the application over time to see if memory usage consistently grows.

- Use a tool such as dotnet-counters to monitor metrics like GC activity, allocation rate, and managed heap size.

2. Capture a Memory Dump

- Once you've identified suspicious memory behavior, capture a snapshot of the process's memory.

- Use dotnet-dump collect -p PID to create a memory dump file containing objects, references, and runtime state.

- Capture multiple dumps at different intervals for comparison.

3. Analyze the Memory Dump

- Analyze the captured dump using dotnet-dump to understand which types are consuming memory.

- Utilize commands like dumpheap -stat to identify objects with high memory usage.

- This can help pinpoint specific types, such as objects of type MyApp.Customer that are taking up significant memory.

4. Identify the Root Cause

- Understand the reference chain leading to the memory-hogging objects.

- Use the gcroot command (dotnet-dump analyze dump.dmp) to trace the path from a GC root to the problematic object.

- For example, a static field may be keeping a list of objects alive, which in turn is holding many customer objects.

- By tracing the references, you can determine why a particular object is not being collected.

5. Fix the Issue

- Once the root cause is identified, address the underlying problem.

- Ensure objects are properly disposed of and that references are removed when no longer needed.

- Refactor the code to eliminate unnecessary static references or loops that maintain references to objects indefinitely.

6. Verify the Fix

- After making changes, re-run the monitoring and testing process to ensure the memory leak has been resolved.

- Verify that memory usage stabilizes after repeated operations, indicating that the GC can now collect unused objects effectively.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

What Is Decisioning Infrastructure for Consumer Platforms?

Consumer platforms make thousands or millions of decisions every second about what users see. A social platform decides which posts appear in a feed. A marketplace decides which listings appear first.

  • Decisioning infrastructure separates candidate generation from ranking and business logic.
  • It determines final item ordering, monetization placements, and records decisions.
  • Incorporates relevance, personalization, context, business rules, and diversity.

Zet: an open-source layer on Laya that knows when to ask a human

Confidence scores aren't error rates. Zet sits on top of Laya and marks every answer sure or unsure, using conformal prediction sets and a Learn-then-Test threshold calibrated per language, so the…

  • Zet is an open-source tool for Laya language model
  • Uses conformal prediction sets for error budgeting
  • Refuses tasks when complexity exceeds 18 scenarios

Six Signatures, Zero Laws: What the White House Super Intelligence Accord Actually Requires

If the entire safety framework for the most powerful technology on the planet were a document, how long would you expect it to be? As of Tuesday, the answer is two pages.

  • White House Accord signed by President Trump and six AI companies on September 29, 2026
  • Accord outlines voluntary commitments for safe AI development without legal enforcement
  • Main components include internal controls, watch team, external auditor, board oversight

Freight Contract PDF Archive: Compress Copies, Store Originals for Signature Fidelity

Short answer: compress a PDF archive's access copies, but store signed originals unchanged. Storage cost matters; signature fidelity decides which bytes are authoritative.

  • Compress PDF contract copies while retaining original signed versions
  • Archive ownership determines proof of signed contracts
  • Align archive choice with server-side logistics template ownership

영지식 증명: 블록체인 확장성, 프라이버시, 상호운용성의 새 시대를 열다

블록체인 혁명은 전례 없는 탈중앙화와 불변성을 약속했지만, 주류 채택을 가로막는 근본적인 난관에 봉착해왔다. 그중에서도 가장 큰 문제는 확장성, 보안성, 탈중앙화를 동시에 달성하기 어려운 '블록체인 트릴레마'다. 더불어 거래 프라이버시의 지속적인 부재와 서로 다른 네트워크 간의 단편화된 상호운용성도 큰 걸림돌이었다.

More from Wednesday 30 September →