Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 18543 [details]
Minimally reproducing program
When using TaskScheduler.FromSynchronizationContext() frequently, memory is leaked very slowly over time.
This appears to be due to TaskScheduler.s_activeTaskSchedulers retaining entries for TaskSchedulers that are no longer in use. Whether this is due to ConditionalWeakTable or something else holding on to a reference has yet to be determined.
Attached is a distilled program for reproducing the issue. Running the program will cause TaskScheduler.FromCurrentSynchronizationContext() to be called roughly every millisecond as part of a Task.Delay.ContinueWith tail-recursive type loop.
If you comment out line 63 and uncomment line 64, you can then observe that the leak does not happen.
We have currently reproduced this on an ARM embedded system as well as an Ubuntu PC, both using Mono 4.2.1.
I will be following up with a test of the latest stable Mono version.
I can now confirm that I have reproduced this in 4.6.2.
Mono JIT compiler version 4.6.2 (Stable 220.127.116.11/08fd525 Mon Nov 14 12:30:00 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
LLVM: supported, not enabled.
Fixed on mono master by a3b053bacf4436f213391b9776d2ab89b8cf3ff7.