-
Notifications
You must be signed in to change notification settings - Fork 65
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
Memory leak under Windows #151
Comments
@TZM-svat We can reproduce what you're seeing and are running some tests, however, at this point the issue seems to be with Blazor, not with Photino. There is no Photino code running at all in this scenario. We are simply hosting a WebView2 control which is hosting Blazor against the .NET runtime. We've found some evidence that System.Timers.Timer may leak memory at times and some evidence that calling InvokeAsync(StateHasChanged) excessively may leak memory. We see that navigating away from the timer page stops the consumption of memory and that it levels off, but returning to the page increases memory use again. Nothing at all happens in Photino when we change pages, so it indicates the memory leak is either in the browser control or in the Blazor code. Taking memory snapshots in the diagnostics window in VS and comparing them shows that no additional managed memory is being consumed, so it does appear to be a leak in native memory. I think the next step would be to figure out how to determine if the leak is in the WebView2 control or in the Blazor code. Interestingly, the longer we leave it running, the more it seems to plateau. Looking at memory in Task Manager, when we start your sample, it's at around 19MB, Over 30 minutes or so, it climbs over 50MB, then it seems to drop back to about 45MB and start climbing again. We're going to leave it run for a few hours and see what happens. It may not be an issue after all. |
Thanks for investigating. Even if the System.Timers.Timer leaks memory, in our real application where we initially stumbled upon the leak we don't use a timer. We're reacting to an incoming SignalR message and after removing the InvokeAsync(StateHasChanged) the memory consumption is steady. I can also confirm the "saw-blade"-like memory usage with rising plateaus, but it gets worse over time not better. After 3 days or so our application consumed over 900MB. Using Jetbrains dotMemory, everything at fault seems to be unmanaged memory. The example with the timer produces no leak using MAUI Hybrid. So if the issue is not with Photino but with WebView2, then MAUI does something additional so the leak does not happen. Another indication that the browser is at fault would be that it runs perfect on Ubuntu with WebGitGTK. |
@TZM-svat We will continue to investigate to see if there is something we can do to mitigate the problem. We left the sample running for several days and it does, as you say, increase memory usage slowly over time (refreshing the UI every 10ms), but memory use is jagged. We noticed that if we use the machine during that time, memory use is quite a bit less than if we just let the app run with no other resource competition. For example, running all day while using the machine for development tasks, memory use did not climb higher than 100MB, hovering around 80MB. If we then leave the machine alone for 12 hours, usage creeps up to around 300MB. If we then navigate away from the counter page, memory eventually drops again. We saw it go down to about 45MB within an hour or so. The more we look into it, the more it appears to be Blazor and/or Edge updating the UI and being lazy about returning memory. We're looking to see if we can find a way to force it to return memory. So far, we haven't found a way. |
Hello,
we are currently developing a .NET 8 Blazor application that runs 24/7 and that basically recieves sensor data from a server in a set inverval (every 1-2 seconds).
Previously we used MAUI Hybrid but switched to Photino since it has a smaller footprint and supports Linux.
Now we are facing a memory leak that only occurs with Photino under Windows 11 (we did not test 10).
On the same device with MAUI Hybrid as a wrapper the memory leak does not occur.
On a device with Ubuntu 24.04 the memory leak does not occur.
I reproduced the issue with the current master and the Photino.Blazor.Sample application. Simply instance a timer on the counter page and call
InvokeAsync(StateHasChanged)
when the timer elapses. The faster the timer runs, the better the leak is visible.The timer simulates the event that triggers every time our application receives a new set of data and needs to refresh the UI.
Under Ubuntu even 10ms are not a problem, the memory usage is perfectly stable with this unrealistic frequency.
Under Windows the Garbage Collection will trigger, but it seems to me some unmanaged memory remains every collection cycle.
I hope this helps and is somehow fixable as we would like to keep using Photino in the future.
Thanks and best regards
Sven
photino.Blazor-master.zip
The text was updated successfully, but these errors were encountered: