using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
namespace MemTest {
static class Program {
[STAThread]
static void Main() {
new Thread( new ThreadStart( ThreadGC ) ).Start();
while( true ) {
Test();
Thread.Sleep( 1 );
}
}
static List<WeakReference> mList = new List<WeakReference>();
static void Test() {
var t = new Thread( new ThreadStart( ThreadTest ) );
lock( mList ) {
mList.Add( new WeakReference( t ) );
}
t.Start();
}
static void ThreadTest() {
Thread.Sleep( 1 );
}
static void Count() {
lock( mList ) {
var tmp = mList.Where( c => c.IsAlive ).ToList();
mList = tmp;
Console.Write( "\n" + mList.Count + "\n" );
// the List grows and grows
}
}
static void DoGC() {
GC.Collect();
Count();
}
static void ThreadGC() {
while( true ) {
if( !running ) break;
Thread.Sleep( 1000 );
DoGC();
}
}
}
}
Memory Leak
In sample code, the list of Threads in WeakReference should not grow
[ ] macOS
[ X] Linux
[ ] Windows
Version Used: 5.11.0.15
Please paste the stacktrace here if available.
Should be fixed via https://github.com/mono/mono/commit/1e3fb99fa35bcd586e846723a74209e980e9f911
I cannot reproduce with Mono 5.11.0.320 (master/693a7c896d9). Could you try downloading latest package from https://jenkins.mono-project.com/view/All/job/build-package-osx-mono/job/master/ and try again? Thank you
Or http://www.mono-project.com/download/nightly/#download-lin on linux.
will try on monday with lastest nightly 5.11.0.300 from https://download.mono-project.com/sources/mono/nightly/
yes. no memory leak with 5.11.0.300.
Thanks.
Most helpful comment
will try on monday with lastest nightly 5.11.0.300 from https://download.mono-project.com/sources/mono/nightly/