<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/exploring-memory-allocation-and-strings-zb6eadmmv" -->

---
title: Exploring memory allocation and strings | daily.dev
description: An exploration of how strings behave in memory in .NET, explaining that despite appearing like value types, strings are reference objects subject to garbage...
canonical: https://daily.dev/posts/exploring-memory-allocation-and-strings-zb6eadmmv
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Exploring memory allocation and strings | daily.dev
og:description: An exploration of how strings behave in memory in .NET, explaining that despite appearing like value types, strings are reference objects subject to garbage...
og:url: https://daily.dev/posts/exploring-memory-allocation-and-strings-zb6eadmmv
og:image: https://api.daily.dev/og/posts/zb6eADMmv.png
og:image:alt: Exploring memory allocation and strings
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Exploring memory allocation and strings

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 8 min read · 0 upvotes · 0 comments

## Summary

An exploration of how strings behave in memory in .NET, explaining that despite appearing like value types, strings are reference objects subject to garbage collection. Covers when strings are allocated, how the CLR optimizes string literals via the intern pool and PE metadata streams, manual interning with String.Intern, the CPU-vs-memory tradeoff of interning, and a real-world example from MyGet.org where interning package IDs reduced memory usage. Offers practical rules of thumb for when interning helps versus hurts.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2016-11-15-exploring-memory-allocation-and-strings>

## Questions this post answers

### Are strings value types or reference types in C#?

Strings in C# are reference types, not value types, even though they behave immutably and support value-based equality comparison with ==. Internally a string holds an immutable array of Char objects and a length property. Because they are objects, strings are allocated on the managed heap and are subject to garbage collection just like any other object.

_Developers reasoning about C# memory behavior can revisit tricky allocation details like this on daily.dev._

### What is the difference between using empty string literal "" and string.Empty in C#?

Using "" causes the CLR to check the intern pool each time, spending CPU cycles even though the value is only stored once in memory. Using string.Empty instead passes around an existing object reference, allocating no extra memory and avoiding the intern pool lookup entirely, making it the more efficient choice.

_Teams debating small C# performance choices like this can keep sharpening that judgment on daily.dev._

### When does string interning in .NET actually help reduce memory usage?

String interning helps when an application holds many long-lived strings but relatively few unique values, since duplicates then collapse into a single intern pool entry instead of consuming heap memory repeatedly. MyGet.org applied this to package IDs, which recur across versions, and saw improved memory usage with negligible CPU cost. It offers no benefit when strings are mostly distinct or short-lived, since interned strings are never garbage collected.

_Anyone weighing interning tradeoffs for their own .NET service can track these memory patterns via daily.dev._

## Similar posts on daily.dev

- [The Fasting Developer: Memory Discipline and GC Awareness in .NET](https://daily.dev/posts/the-fasting-developer-memory-discipline-and-gc-awareness-in-net-5yq85h552) · We Are .NET · 12 upvotes · 0 comments
- [strings](https://daily.dev/posts/strings-2yiygpffb) · Inside Java · 0 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/exploring-memory-allocation-and-strings-zb6eadmmv)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Exploring memory allocation and strings","url":"https://daily.dev/posts/exploring-memory-allocation-and-strings-zb6eadmmv","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/exploring-memory-allocation-and-strings-zb6eadmmv"},"datePublished":"2026-10-04T13:04:27.357Z","dateModified":"2026-10-04T13:09:17.729Z","description":"An exploration of how strings behave in memory in .NET, explaining that despite appearing like value types, strings are reference objects subject to garbage...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/00b022ef58d9e5317e3df67bd44a07a4?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/00b022ef58d9e5317e3df67bd44a07a4?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/exploring-memory-allocation-and-strings-zb6eadmmv","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"Exploring memory allocation and strings"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/exploring-memory-allocation-and-strings-zb6eadmmv#faq","mainEntity":[{"@type":"Question","name":"Are strings value types or reference types in C#?","acceptedAnswer":{"@type":"Answer","text":"Strings in C# are reference types, not value types, even though they behave immutably and support value-based equality comparison with ==. Internally a string holds an immutable array of Char objects and a length property. Because they are objects, strings are allocated on the managed heap and are subject to garbage collection just like any other object. Developers reasoning about C# memory behavior can revisit tricky allocation details like this on daily.dev."}},{"@type":"Question","name":"What is the difference between using empty string literal \"\" and string.Empty in C#?","acceptedAnswer":{"@type":"Answer","text":"Using \"\" causes the CLR to check the intern pool each time, spending CPU cycles even though the value is only stored once in memory. Using string.Empty instead passes around an existing object reference, allocating no extra memory and avoiding the intern pool lookup entirely, making it the more efficient choice. Teams debating small C# performance choices like this can keep sharpening that judgment on daily.dev."}},{"@type":"Question","name":"When does string interning in .NET actually help reduce memory usage?","acceptedAnswer":{"@type":"Answer","text":"String interning helps when an application holds many long-lived strings but relatively few unique values, since duplicates then collapse into a single intern pool entry instead of consuming heap memory repeatedly. MyGet.org applied this to package IDs, which recur across versions, and saw improved memory usage with negligible CPU cost. It offers no benefit when strings are mostly distinct or short-lived, since interned strings are never garbage collected. Anyone weighing interning tradeoffs for their own .NET service can track these memory patterns via daily.dev."}}]}
```

