5 ms·
I'd like to see a real, useful implementation of weak references, for use in value caches, or a way to manually take over garbage collection for some objects.
by pfooti 8y ago
I'd like to see a real, useful implementation of weak references, for use in value caches, or a way to manually take over garbage collection for some objects.
Basically if I want to keep a cache of expensive objects that will grow monotonically, I need to do a lot of work to make sure I'm not leaking memory right now, but if I could instead store in a Map<string, weakref>, it'd be much easier, things could go out of ref and I could deal with that.
- ralusek 8y agoYou're aware of WeakMap and WeakSet, right? You can't key by strings, but I'm not sure you'd want to.
- pixelcort 8y agoYes, but a weakref by string or number would be quite useful for ORM caching.
- pfooti 8y agoYeah weakmap and weakset basically do the opposite of what I want. The keys are weakly held rather than the values, which does no good for an ORM cache. One cannot even iterate over the keyset in a weakmap (so you can't do a lousy o(n) lookup version of what I want.