loke
10/28/2025, 3:51 PMWeakReference. However, once the reference is cleared, I need to remove the key from the hashmap.
In the Java backend, I can do this by leveraging ReferenceQueue and check when a reference has been dropped, and then remove the corresponding key (tracked in a separate hashmap).
But, I struggle to figure out a way to achieve this using the JS and Native backends. To be honest, I'm not sure these backends have the necessary infrastructure to make this possible. There certainly doesn't seem to be anything similar to ReferenceQueue. Using Cleaner is unfortunately not sufficient, since I can't change the code so that it works with wrapper objects. The thing that is returned from the namespace object has to be of type Symbol, not SymbolWrapper which includes a Cleaner.loke
10/28/2025, 3:52 PMstreetsofboston
10/28/2025, 3:57 PMloke
10/29/2025, 1:03 AMReferenceQueue, but in Native, it seems that is not possible unless I add an extra field to the Symbol object (a reference to the Cleaner instance). But this is what I want to avoid, since I don't want to add extra fields to the Symbol object.CLOVIS
10/29/2025, 9:26 AMloke
10/31/2025, 1:42 PMloke
10/31/2025, 1:43 PMCLOVIS
10/31/2025, 2:45 PMCLOVIS
10/31/2025, 2:45 PMloke
10/31/2025, 3:35 PMloke
10/31/2025, 3:36 PMReferenceQueue implementation in the JVM is really ideal, and I'm not sure the other platforms are powerful enough to implement this.CLOVIS
10/31/2025, 3:37 PMHashMap<K, WeakReference<T>> where get() only removes the current element if it's not valid anymore (instead of removing all the previous ones too). Maybe with a heuristic that every 1000 writes it does a full cleanup. That will lead to more memory usage, but it could be much faster.loke
10/31/2025, 3:39 PMfor (i = 0...1000000) { internSymbol("name"+i) }loke
10/31/2025, 3:40 PMloke
10/31/2025, 3:40 PMCLOVIS
10/31/2025, 3:40 PMloke
10/31/2025, 3:40 PMloke
10/31/2025, 3:41 PMloke
10/31/2025, 3:41 PMCLOVIS
10/31/2025, 3:41 PMloke
10/31/2025, 3:42 PMloke
10/31/2025, 3:42 PM