0

I know that string pools are associated with processes. And it will be recycled when the owner process exits or an application domain is unloaded.

But I wonder if an application is long running, will the string pool leak memory?

user3738870
  • 1,415
  • 2
  • 12
  • 24
shengjie
  • 1
  • 1
  • Only if you abuse `String.Intern()`. The [notes about performance](https://learn.microsoft.com/en-us/dotnet/api/system.string.intern?redirectedfrom=MSDN&view=netframework-4.7.2#performance-considerations) tell you all you need to know. – spender Sep 23 '18 at 00:26
  • The short answer is no. No general-use programming construct will unless it has a bug or was designed by complete morons. (Or unless you're using it wrong, which takes some work in a GC language. – zzxyz Sep 23 '18 at 01:43
  • @spender Even if someone don't use `String.Intern()` and simply write `string A="Z"; string B="Z";` still there are only one object in string pool with value "Z" and hence it seems that it still only released when CLR terminates. – Masoud Keshavarz Sep 23 '18 at 09:25
  • In addition it seems that to prevent interning using CompilationRelaxationsAttribute is vital. https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.compilationrelaxationsattribute?view=netframework-4.7.2 – Masoud Keshavarz Sep 23 '18 at 09:33

0 Answers0