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

226
Views
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 answers
Answer question

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 Report
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!