Wondering how I can dispose of a variable. If this is my code...
string myCode = GetMyCode();
myCode.Dispose(); // this is what I am trying to do
What is the best way of disposing this variable because I don't want it to stay in memory because of its sensitivity.
VulpesPosted Nov 17, 2014, 11:20 AM
You can do this quite easily using unsafe code but, so you don't have to compile with the /unsafe switch on, I'll show you another way which uses P/Invoke to call the API function RtlZeroMemory:
The output is:
There's also something called a SecureString but whether it would be suitable here depends on how the string is being constructed in the first place. Check out:
http://msdn.microsoft.com/en-us/library/system.security.securestring(v=vs.110).aspx