WebAssembly-specific issue : chrome run 1 hour later , crash
Describe the bug
I use js interop , and memory still growth.
1:c# code
<input type="button" class="btn btn-primary" onclick="Operate(this)" value="开始" />
<div id="JsonContent">
</div>
@functions {
static Rectifyf.FlowsheetBase Rectifyf = new Rectifyf.FlowsheetBase();
static Type t;
public static string result;
public static int total = 0;
protected override async Task OnInitAsync()
{
t = Rectifyf.GetType();
}
protected override void OnAfterRender()
{
base.OnAfterRender();
}
[JSInvokable]
public static string RUNRectifyf()
{
Rectifyf.Run();
result = "";
total = 0;
PropertyInfo[] pro2 = t.GetProperties();
foreach (PropertyInfo item in pro2)
{
string FieldName = item.Name;
PropertyInfo property = t.GetProperty(FieldName);
object o = property.GetValue(Rectifyf, null);
string Value = Convert.ToString(o);
if (property.PropertyType.Name.Contains("[]"))
{
Value = "";
double[] a = o as double[];
for (int i = 0; i < a.Length; i++) {
Value += a[i] + ",";
}
}
result += item.Name + "--->" + item.MemberType + "--->" + item.PropertyType +"--->"+ Value +";";
total += 1;
}
return result;
}
}
2: Javascript code
var count = 0; var GO;
var r = function sfRun() {
window.clearTimeout(GO)
DotNet.invokeMethodAsync("BlazorApp1", 'RUNRectifyf').then(function (parm) {
count++;
$("#JsonContent").html(parm);
GO = window.setTimeout(function () {
r();
}, 500);
});
}
function Operate(obj) {
r();
}
when I run my chrome , the memory still growth.
maybe setTimeout function create a lot of DotNet, how to fix it?
maybe it is out of memory, not memory leak? https://github.com/mono/mono/issues/10250
String manipulation here is going to lead to memory hikes plus gc pressure. Replace with StringBuilder would be my first course of action.
@dallancarr thank you, I want to loop run C# code ,and deliver some variable value to js , then show in the html (or svg). Receive the value entered by the user at the same time. It seems that it is not string problem, today I will do a test use StringBuilder.
Thanks for contacting us, @w8w8w8. @SteveSandersonMS, can you please look into this? Thanks!
We heard from the Mono team that they identified one or more memory leaks with the Mono WebAssembly runtime (in particular, relating to GC internals), and have since fixed them. So my hope would be that this issue would cease once we update to a newer runtime.
thanks, Looking forward to the new runtime. hope use blazor at work. @mkArtakMSFT , @SteveSandersonMS
We've updated to a new version of mono that should fix this. If you're still having problems it would be best to log these issues at github.com/mono/mono
@rynowak thank you answer me. I will install vs2019 and try it! thanks