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

Possible memory leak? #355

Closed
cerkoid opened this issue Nov 3, 2022 · 3 comments
Closed

Possible memory leak? #355

cerkoid opened this issue Nov 3, 2022 · 3 comments

Comments

@cerkoid
Copy link

cerkoid commented Nov 3, 2022

Hi.

Is it possible that Fluxor Store instances are not garbage collected?
I tested large blazor server app and instances of Store, App, etc. are kept in memory, so I started investigating where is the problem...
Maybe problem is in my test, since I monitored memory while pressing F5 in browser, just to check if there is some potential problem :)

How to reproduce:
Create new blazor server project, in VS profile memory. While pressing F5 and comparing memory snapshots, there is always only 1 instance of App class and memory looks clean.

Now add Fluxor in the mix like:
builder.Services.AddFluxor(o =>
{
o.ScanAssemblies(/main assembly/);
}
And add
<Fluxor.Blazor.Web.StoreInitializer /> to App.razor

Retry VS memory profile while hitting F5 and Store instances are not GC-ed even though Dispose methods are being called (2x per store instance?). I couldn't find what is holding reference to instances, it looks like sth in DI system..., it could be that blazor is not recycling connections / instances, but don't know why app without fluxor is not showing such symptoms maybe because fluxor is using JS calls and blazor connection lifecycle is not GCed instantly...

I looked all of the source code of Fluxor but couldn't find some obvious problem... maybe problem even does not exist, but adding fluxor to an app changes memory footprint / consumption quite a bit...

Does anyone have an idea, why memory would behave like that absent some obvious memory leak?

Regards.

@mrpmorris
Copy link
Owner

Blazor Server holds onto the state in case the user reconnects.

@cerkoid
Copy link
Author

cerkoid commented Nov 3, 2022

Ok, I see what you mean. But why then DI system calls Dispose on store but GC keeps instance in memory?

@cerkoid
Copy link
Author

cerkoid commented Nov 4, 2022

Ok I found out what is the root cause of my observations. It's not about user reconnecting, but System.Text.Json caching some stuff in .NET 7. That's why behaviour is totally unexpected...

dotnet/aspnetcore#44062
dotnet/runtime#76548

@cerkoid cerkoid closed this as completed Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants