Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda