Skip to content

BlazorServer doesn't release circuits/component instances after 25mins+forced GC2 #44062

@chrdlx

Description

@chrdlx

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Blazor component instances and circuit objects/instances don't seem to be released from memory after 25+ minutes and forced 2nd generation garbage collection using the basic out of the box Blazor Server template. I tried to follow the recommendations from @javiercn in this post #30210 (comment) to test this.

Expected Behavior

The amount of Counter instances & Circuits should go to zero after 10/20/30 minutes and a forced garbage collection ( GC.Collect(2, GCCollectionMode.Forced);).

Steps To Reproduce

  1. Create a default Blazor Server template app in Visual Studio 17.4.0 Preview 2.
  2. Go to the Counter.razor component and change the method to

private void IncrementCount() { GC.Collect(2, GCCollectionMode.Forced); }

as recommended by @javiercn here #30210 (comment) so we can force a GC collect after 20 minutes.

  1. Set the build mode to *Release
  2. Execute the application
  3. Click on the Counter tab button so we navigate to the counter page.
  4. Now on the counter page, press F5 (refresh page) 10 times.
  5. Open the Diagnostics Tool in VS and take a memory snapshot.
  6. Search in the snapshot for *Counter and *Circuits.circuit

image
and
image

So you can see there're 11 instances (1 initial request + 10 refreshes) of the component as expected in memory, and the related circuits.

  1. Wait 10 minutes.

  2. Take a new snapshot.
    image
    image
    Component instances & circuits still there after 10 minutes.

  3. Wait another 10 minutes (just in case)

  4. Take a new snapshot

image
image

  1. So we waited 20 minutes (the double recommended by javier), all the instances are still there... So now let's trigger a forced GC collect using the Counter button for which we changed the code:

image

We can see a GC has occured.

  1. Take another snapshot to see if after 25+ minutes and a forced GC, Counter components & circuit instances have been released.
    image

image

So nothing has changed, 11 instances are still there after almost an hour, and a forced GC collection.

Just in case I forced GC a couple more times.
image

Still nothing is released.

Exceptions (if any)

No response

.NET Version

7.0.100-rc.1.22431.12

Anything else?

What I've tried to see if this gets fixed:

 builder.Services.AddServerSideBlazor(options => {
                options.DisconnectedCircuitMaxRetained = 0;
                options.DisconnectedCircuitRetentionPeriod = TimeSpan.FromSeconds(0);
            });
  1. Changing the GC mode to Workstation.

  2. Debug & Release modes.

  3. Closed the browser completely (but left the server running).

Nothing seems to make .NET to release Counter component instances & circuits after half an hour.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions