aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

WebAssembly-specific issue : chrome run 1 hour later , crash

Open w8w8w8 opened this issue 8 years ago • 7 comments

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

w8w8w8 avatar Dec 03 '18 14:12 w8w8w8

String manipulation here is going to lead to memory hikes plus gc pressure. Replace with StringBuilder would be my first course of action.

dcarr42 avatar Dec 04 '18 13:12 dcarr42

@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.

w8w8w8 avatar Dec 05 '18 00:12 w8w8w8

Thanks for contacting us, @w8w8w8. @SteveSandersonMS, can you please look into this? Thanks!

mkArtakMSFT avatar Jan 16 '19 22:01 mkArtakMSFT

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.

SteveSandersonMS avatar Jan 16 '19 23:01 SteveSandersonMS

thanks, Looking forward to the new runtime. hope use blazor at work. @mkArtakMSFT , @SteveSandersonMS

w8w8w8 avatar Jan 17 '19 00:01 w8w8w8

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 avatar Mar 15 '19 16:03 rynowak

@rynowak thank you answer me. I will install vs2019 and try it! thanks

w8w8w8 avatar Mar 17 '19 07:03 w8w8w8