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

234
Visualizações
Difference between WeakSet<T> and Set<Weakref<T>>

I was recently wondering if there is any drawback for Set<Weakref<T>> over WeakSet<T>.

Pros:

  • The set is iterable

Cons:

  • The set must be filtered from no longer valid references

Am I missing something or is this almost a win-win situation? Would the Set<Weakref<T>> version prevent the garbage collector from collecting?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What you missed:

WeakSets are collections of objects only. They cannot contain arbitrary values of any type, as Sets can.

The number of objects or their traversal order is immaterial, so a WeakSet is more suitable (and performant) than a Set for tracking object references, especially if a very large number of objects is involved.

MDN source

Set<Weakref<T>> will not prevent GC. Also note that WeakRef is not supported in Opera but WeakSet is.

about 4 years ago · Juan Pablo Isaza Relatório
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