-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 when marshalling Delegate to native code #6161
Comments
Hi, thanks for the test case. |
Mono JIT compiler version 5.4.1.6 (tarball Wed Nov 8 16:59:44 UTC 2017) |
Looks like previously reported leaks of 5.4 were fixed by 4cf2b5f#diff-889eecc0e02f623fc21d69e97f0983c4 Profiler not show memory leaks, but memory of the sample application attached here still is growing rapidly after our test on 5.11. Looks like stub functions generated for delegates marshaling are never deleted from memory (mono/metadata/marshal.c: mono_delegate_to_ftnptr()). |
Memory is released when the delegate is collected. |
I can repro the leak. I'll take a look at it. |
I can confirm this leak too (Mono 5.0). Waiting eagerly for a fix... Thanks! |
This is a leak in mono_delegate_to_ftnptr when freeing the native MonoMethod signature. It happens because too much sharing of MonoType's that triggers memory corruption and thus we addressed that by not freeing the signatures. As a workaround, use delegates to static methods, which don't suffer from this issue and have much superior performance. |
Thanks, Rogrigo! So this bug was introduced by trying to conceal another bug, right? Are there plans to address the underlying issue to break this vicious cycle? Static delegates will require to explicitly pass |
In our project we send callback delegate to native code and found a memory leak at runtime.
This is a sample project that reproduce the problem.
"libnative" is a simple test programm that only execute callback.
Full test project added to attachement.
This leak reproduced on Mac and Linux on Windows all fine. With mono-boehm leak not reproduced, only with SGen.
Profiler show memory leak at:
Leak: 0x7f81e74001c0 size=16 zone: DefaultMallocZone_0x1068f1000
0x03b0600e 0x00000000 0x00000000 0x00000000 .`..............
Call stack: [thread 0x7fffb321e340]: | start | main | mono_main | mono_jit_exec | do_exec_main_checked | do_runtime_invoke | mono_jit_runtime_invoke | 0x106a0d427 | mono_delegate_to_ftnptr | mono_jit_compile_method_with_opt | mono_jit_compile_method_inner | mini_method_compile | mono_save_seq_point_info | mono_seq_point_info_new | monoeg_malloc0 | calloc | malloc_zone_calloc
We really like the Mono project and enjoy using it on our servers, but because of the leaks we have to restart the server every 24 hours.
Please help us :)
leaks_mono-sgen.zip
MonoPInvokeLeak2.zip
The text was updated successfully, but these errors were encountered: