Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
Memory leak tests with .net core

I am working on a big project that has lots of classes and those classes has incoming references. Before we were using the .NET Framework, we were using the WeakReference class to see if the object got disposed. Recently we migrated our project to .net core 5, and all of a sudden that test with object disposing test started to fail. After a little bit(quite a bit actually) research, find out that WeakReference doesn't function the same way as it did in .NET Framework.

        Student student = new Student();
        WeakReference weakRef = new WeakReference(student);
        student.Dispose();
        student = null;
        GC.Collect();
        GC.WaitForPendingFinalizers();
        GC.Collect();
        var isAlive = weakRef.IsAlive;

Any ideas how I can test whether the object got disposed properly? I could put some kind of a log in the disposing method, but that still doesn't guarantee that the object is disposed. Purpose of the question is not to test whether .net core disposing my object, I would like to know if there are other objects referencing to it that is preventing the object from being disposed.

PS: I also put Thread.Sleep with while loop to see if the object will get disposed later on, but that didn't happen even after 30 mins.

I tried using the JetBrains dotMemoryUnit, and that also acted the same as WaekReference. It is a great tool that shows all the issues and eliminating the problem is so quick.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!