According to the documentation, the memory limit for a consumption plan azure function should be 1.5 GB. While running some tests because we received quite a few OutOfMemory exceptions we ran into the following behavior.
Expected: Execute the for loop about 15 times to allocate about 1.5 GB of memory, then fail with an OutOfMemory exception
Actual: Executes a single loop, then fails with an OutOfMemory exception
I am using an Azure Function v4, .NET 6.0, with the following code:
public static class Function
{
private const int MByteSize = 1_048_576;
[FunctionName("MemoryTestAzureFunction")]
public static async Task Run(
[ServiceBusTrigger("dummy", Connection = "ServiceBusConnectionString")]
string myQueueItem, ILogger log)
{
log.LogInformation("> Started Run: {StartTime}", DateTime.UtcNow.ToLongTimeString());
LogMemory(log);
var buffer = new byte[20][];
for (var i = 0; i < 20; i++)
{
log.LogInformation(" > Allocating 100 MB");
buffer[i] = new byte[MByteSize * 100];
LogMemory(log);
log.LogInformation(" > Filling 100 MB");
Array.Fill