Processing large arrays or strings eating up memory? Span<T> lets you work with slices of memory without allocating new arrays. The Problem – Traditional Approach: // BAD: Creates new array on every call public byte[] ProcessChunk(byte[] data, int start, int length) { byte[] chunk = new byte[length]; // Heap allocation Array.Copy(data, start, chunk, 0, length); […]
Tag: Garbage Collection
C# Performance: Use Span
.NET Core: Fix Memory Leaks by Understanding IDisposable and Using Patterns
Your .NET application’s memory usage grows infinitely? You’re probably not disposing resources properly. Here’s the complete guide. The Memory Leak – Classic Example: // WRONG: Memory leak public async Task ProcessOrdersAsync() { var dbContext = new ApplicationDbContext(); var orders = await dbContext.Orders.ToListAsync(); // Process orders… // dbContext never disposed = connection stays open = memory […]

