-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
51 lines (42 loc) · 1.63 KB
/
Program.cs
File metadata and controls
51 lines (42 loc) · 1.63 KB
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
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Threading;
namespace OomKillDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("OOMKill Demo Application Starting...");
Console.WriteLine($"Initial memory: {GC.GetTotalMemory(false) / 1024 / 1024} MB");
// List to hold allocated memory blocks
var memoryHog = new List<byte[]>();
// Allocation size: 10 MB per iteration
const int blockSize = 10 * 1024 * 1024;
int iteration = 0;
try
{
while (true)
{
iteration++;
// Allocate memory block
byte[] block = new byte[blockSize];
// Fill with data to ensure memory is actually allocated
for (int i = 0; i < block.Length; i += 4096)
{
block[i] = (byte)(iteration % 256);
}
memoryHog.Add(block);
long totalMemoryMB = GC.GetTotalMemory(false) / 1024 / 1024;
Console.WriteLine($"Iteration {iteration}: Allocated {iteration * 10} MB total, GC reports {totalMemoryMB} MB");
// Small delay to make the process observable
Thread.Sleep(500);
}
}
catch (OutOfMemoryException)
{
Console.WriteLine("OutOfMemoryException caught! This shouldn't happen in Kubernetes - OOMKiller should terminate the process first.");
}
}
}
}