3

How can I clear all interned strings in linqpad?

Looking at this example :

//var asd="asd";
string s = new string(new  []{'a','s','d'});
Console.WriteLine (string.IsInterned(s));

It always return null , which is fine.

But once I un-remark the first line it always yield "asd" even if I remark it again.

It seems that the only solution is to close the program and start it again.

p.s. : in visual studio it's always returns the desired results (console mode).

Royi Namir
  • 144,742
  • 138
  • 468
  • 792
  • this SO thread might offer some reason why you are having problems clearing it: http://stackoverflow.com/questions/2365272/why-net-string-is-immutable In order for you to get the desired results in a console app, don't you have to uncomment that line and rebuild? which is the same as unloading and reloading LINQPad..no? – Hardrada Feb 24 '14 at 07:16

1 Answers1

3

LINQPad maintains the AppDomain between runs, so everything that's static will remain in memory. You can change this behavior by going to Edit > Preferences > Advanced > Always use fresh application domains.

While the above is true, it seems string interning is performed at a process level (see here). So there's no way to reset that besides restarting.

Eli Arbel
  • 22,391
  • 3
  • 45
  • 71
  • 2
    "Cancel all threads and reset" (Shift+Ctrl+F5) is another way to clear the AppDomain. But as Eli says, interning happens at a process level, so it won't have any effect in this case. – Joe Albahari Feb 24 '14 at 08:21