Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process Memory growing in server-side Blazor only on button press. #10623

Closed
bitBrainResearch opened this issue May 29, 2019 · 3 comments
Closed
Assignees
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue investigate

Comments

@bitBrainResearch
Copy link

I noticed this when testing my own blazor server-side project I'm working on. When I clicked a button repeatedly, Process Memory in Diagnostic Tools in Visual Studio would jump by a megabyte almost every time. I eliminated every part of my own code until there was nothing left but a button and it still happened.

I started a Blazor client-side project.
I went to the Counter page.
I clicked Click Me repeatedly.
It did not display the same behavior.

I started a Blazor server-side project.
I repeated the steps above.
Process Memory goes up by a megabyte every couple clicks.

I tried another experiment suggested by a coworker. I created a function and inside the function I put
StateHasChanged();
Task.Delay(30).ContinueWith(t=> CallThisFunctionAgain());

This also resulted in Process Memory growing but I don't know if there's some other reasonable explanation for this happening.

This could easily be the expected behavior. I have no idea. It seems like a simple button press that does not do anything (I removed the onclick handler in my own project and Counter should only be incrementing an integer) should not bump up the process memory.

I expected to see no change in the process memory.

.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview5-011568
Commit: b487ff10aa

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\

Host (useful for support):
Version: 3.0.0-preview5-27626-15
Commit: 61f30f5a23

.NET Core SDKs installed:
2.1.504 [C:\Program Files\dotnet\sdk]
2.1.700-preview-009597 [C:\Program Files\dotnet\sdk]
2.1.700-preview-009601 [C:\Program Files\dotnet\sdk]
2.1.700-preview-009618 [C:\Program Files\dotnet\sdk]
2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
2.2.104 [C:\Program Files\dotnet\sdk]
2.2.300-preview-010046 [C:\Program Files\dotnet\sdk]
3.0.100-preview5-011568 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components investigate labels May 29, 2019
@mkArtakMSFT
Copy link
Member

Thanks @bitBrainResearch.
From your observations, does the memory goes up indefinitely, or is it being GCed periodically and goes back to normal?

@mkArtakMSFT mkArtakMSFT self-assigned this May 31, 2019
@mkArtakMSFT mkArtakMSFT added this to the 3.0.0-preview7 milestone May 31, 2019
@bitBrainResearch
Copy link
Author

I did some more testing on it today.

This code:
System.GC.Collect(); System.GC.WaitForPendingFinalizers();

Would stop the clicking from affecting process memory. For many clicks. Then it will start again.

Which seems to me like the garbage collection is working but the data in VS isn't being updated correctly.

The best I could describe the behavior is if you had an array and the array was resized and an element added every time you click. Then you did something which erased half the array (by setting an index). Now the array is not resized to the new size. So you add things with clicks and it fills up until it hits the original size and then starts expanding again.

I don't know if that makes any sense. I have no idea what's really going on. But that seemed like the best way I could describe the behavior I see.

I looked out at task manager and neither chrome nor visual studio show an increase in memory usage when I'm testing this out.

I'd like to try to max out ram and see if I could get a crash or something but that would take a lot of clicking :D

@mkArtakMSFT
Copy link
Member

What you're experiencing is actually normal. There are certain criteria-s for GC to kick in and reclaim unused memory. If you remove the code as you shouldn't do that on the click handler, GC will kick in when necessary and clean up whatever is necessary.

I'm closing this issue, as we have a separate issue where we plan to do some memory related tests on Blazor, which will cover this: #10472

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Jun 4, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue investigate
Projects
None yet
Development

No branches or pull requests

2 participants