dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.03k stars 4.67k forks source link

[mono] thread not been gc when method execute end. #106176

Open srxqds opened 1 month ago

srxqds commented 1 month ago

we have the test code show below:

public void TestGetSingleton()
{
    TestGetSingletonThreadSafe();

    void TestGetSingletonThreadSafe()
    {
        void MyThreadMethod()
        {
            FModuleManager.Get();
        }

        Thread thread = new Thread(new ThreadStart(MyThreadMethod));

        thread.Start();
        FModuleManager.Get();
        thread.Join();

    }
}

// and the FModuleManager code:
public partial class FModuleManager : ScriptingWrapperOfType
{
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern FModuleManager Get();
}

we have usemono_gc_walk_heap analyze the FModuleManager not been gc, No other code references.

gc_heap_walk the alc Engine_1(000002B71AF875A0) has object(UnrealEngine.FModuleManager) 000002B77455B060 live

srxqds commented 1 month ago

it seems not free the thread stack??

hez2010 commented 1 month ago

try changing the line Thread thread = new Thread(new ThreadStart(MyThreadMethod)); to using Thread thread = new Thread(new ThreadStart(MyThreadMethod));

srxqds commented 1 month ago

try changing the line Thread thread = new Thread(new ThreadStart(MyThreadMethod)); to using Thread thread = new Thread(new ThreadStart(MyThreadMethod));

the Thread class not implemented System.IDisposable

srxqds commented 4 days ago

anyone can help to review this problem?