Gof Flyweight

Flyweight in modern Java: sharing one immutable instance across many logical occurrences to reduce retained memory, with benefits dependent on duplicate lifetimes and lookup cost. Covers the intrinsic/extrinsic split, why cheap TLAB allocation does not make reclamation free, the memory arithmetic deciding whether a cache entry costs more than the object it saves, string deduplication and boundary canonicalisation as cheaper alternatives, the unbounded intern map as a leak, and the == trap. Use when object pooling or interning is proposed, when a heap dump shows millions of duplicate values, when someone suggests caching small objects for speed, when a shared instance is mutable, or when a flyweight cache is described as a distributed cache. Does not cover application-level caching policy (caching-strategies), finding the duplicates (heap-dump-analysis), allocation cost in general (allocation-profiling), or one-instance-with-global-access (gof-singleton).

robsonkades Updated

File contents

robsonkades/agent-skills/tree/main/skills/gof-flyweight commit 43a06c7e79

Frequently asked questions

npx skillmds@latest add robsonkades/gof-flyweight