-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
42 lines (34 loc) · 1.01 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Example program that allocates more and more memory to a list pinned in memory.
var people = new List<Person>();
var exit = false;
while (!exit)
{
for (var i = 0; i < 10_000; i++)
{
people.Add(new Person(
id: i,
firstName: $"John #{i}",
lastName: "Doe"));
}
Console.WriteLine($"Take a memory dump now.");
Console.WriteLine($"Person count: {people.Count:N0}");
Console.WriteLine($"Memory used: {GC.GetTotalMemory(false):N0} bytes");
Console.WriteLine("Leak more memory (y/n)");
var answer = Console.ReadKey();
exit = answer.Key != ConsoleKey.Y;
Console.WriteLine();
}
Console.WriteLine("Bye!");
internal sealed class Person
{
internal Person(int id, string firstName, string lastName)
{
Id = id;
FirstName = firstName;
LastName = lastName;
}
public int Id { get; }
public string FirstName { get; }
public string LastName { get; }
private char[] Details { get; } = new char[10_000];
}