dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.14k stars 4.71k forks source link

Blazor Wasm limited to 1 GB of memory #102574

Open verdie-g opened 5 months ago

verdie-g commented 5 months ago

Description

OutOfMemoryExceptions are thrown after allocating more than ~1 GB in a Blazor Wasm app.

This is a duplicate of https://github.com/dotnet/aspnetcore/issues/55694 that got closed but the issue is not solved.

Reproduction Steps

  1. dotnet new blazorwasm -n BlazorTest
  2. Add this method to Home.razor
    protected override void OnInitialized()
    {
    const int bufferSize = 64 * 1000;
    const int oneGig = 1_000_000_000;
    List<byte[]> list = [];
    for (int i = 0; i < oneGig / bufferSize; i += 1)
    {
        list.Add(new byte[bufferSize]);
    }
    }
  3. dotnet run --project BlazorTest
  4. Observe OOM in the console

Expected behavior

Because wasm uses a 32-bits addressing, I would expect to be able to use 4 GB of memory.

Actual behavior

OOM is thrown after allocating ~1 GB of memory.

System.OutOfMemoryException: Out of memory
   at BlazorTest.Pages.Home.OnInitialized() in /home/gverdier/repos/BlazorTest/Pages/Home.razor:line 17
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

Regression?

No response

Known Workarounds

No response

Configuration

.NET: 8.0.100 OS: Ubuntu x64 Browser: Google Chrome 125

Other information

No response

dotnet-policy-service[bot] commented 4 months ago

Tagging subscribers to this area: @brzvlad See info in area-owners.md if you want to be subscribed.

lewing commented 4 months ago

Did you try setting EmccMaximumHeapSize to something larger?

verdie-g commented 4 months ago

I've just tried setting

<EmccMaximumHeapSize>4294967296</EmccMaximumHeapSize>

in my csproj but it still OOMs.

lewing commented 4 months ago

can you try setting EmccInitialHeapSize to something large as well?

verdie-g commented 4 months ago

Same behavior with

<EmccInitialHeapSize>3000000000</EmccInitialHeapSize>
<EmccMaximumHeapSize>4294967296</EmccMaximumHeapSize>