Skip to content

Instantly share code, notes, and snippets.

@wk-j
Created December 3, 2020 16:20
Show Gist options
  • Save wk-j/5cd7e585baafcb476b24441deab7a32c to your computer and use it in GitHub Desktop.
Save wk-j/5cd7e585baafcb476b24441deab7a32c to your computer and use it in GitHub Desktop.
Leak
using System.IO;
using System.Reflection;
GetResource1("MyApp.Program.cs");
GetResource2("MyApp.Program.cs");
ReadFile();
static string GetResource1(string path) {
var asm = Assembly.GetEntryAssembly();
var stream = asm.GetManifestResourceStream(path);
var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
static string GetResource2(string path) {
var asm = Assembly.GetEntryAssembly();
using var stream = asm.GetManifestResourceStream(path);
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
static void ReadFile() {
new FileStream("a.txt", FileMode.Open, FileAccess.Read);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment