mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.23k stars 139 forks source link

Finalizable objects require multiple garbage collection to clean up and may cause performance issues #378

Closed sallyjwhite closed 1 year ago

sallyjwhite commented 1 year ago

We have a production version of Blazor Server running on Azure, that extensively uses Fluxor. We were investigating a memory leak and have found that the application is holding on to Flxuor Subscriptions preventing the subscription from being removed through the GC. Screenshot shows 15K Fluxor.DisposableCallbacks in the "Finalizable objects require multiple garbage collection to clean up and may cause performance issues" memory analysis report on Azure after 15 hours of up time and a maximum of 40 users. image

We did some digging and found that if we tweaked the UnsubscribeFromAllActions in ActionSubscriber.cs class to include:

            IEnumerable<object> subscribedInstances =
                instanceSubscriptions
                    .Select(x => x.Subscriber)
                    .Distinct();
            foreach (object subscription in subscribedInstances)
            {
                if (SubscriptionsForInstance.ContainsKey(subscription))
                    SubscriptionsForInstance.Remove(subscription);
            }

The Fluxor.DisposableCallbacks dropped to around 700

Complete Class: ActionSubscriber.txt

Would you consider adding this to your codebase?

mrpmorris commented 1 year ago

Hiya

Could you fork the repo and submit a PR to branch release/5.7, please?

I'll check the diff, and then we can discuss what is happening.

Thanks!

mrpmorris commented 1 year ago

Released in 5.7