Usefulness and Uses of Weak Reference and Finalization Registry in Real Life
summary
Shows how to build a weak-value cache using a Map from image names to WeakRef objects and a FinalizationRegistry that deletes map keys when targets are collected; code returns a memoized loader that calls ref() and regenerates images on miss, and registers entries after inserting them. Demo is a photo-collage app that first downloads four images, later serves 3 of 4 from cache (75% fewer network requests); warns that cleanup relies on nondeterministic GC and finalizers are not guaranteed to run.
AI-written summary · about
chapters (6)
- 0:00Introduction to features
- 2:02Understanding WeakRef
- 5:06WeakRef implementation
- 8:11Using finalizers
- 9:34Combined usage
- 11:11Practical application
related talks
27mweak collections, ephemerons, and private fields by Sigurd Schneider | JSCAMP 2019
21mMemory: Don't Forget to Take Out the Garbage
24mTrash Talk - Understanding Memory Management
36mTaking an Image Editor Offline
47mCaching beyond simple put and gets
27mCaching for Cash
31mApplication Cache: Douchebag
01h 00mResponsive Images
