Loading lesson…
Level 1 · Apprentice0 XP
Share the identical part of many small objects to save memory.
Step 1 / 5
ProblemA game map has a million tree objects. Each stores its own copy of the same 2 MB texture. The game runs out of memory.
← → step
Before this: Composite: trees of the same thing
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Create 1,000,000 objects that each hold a 1 KB shared style, first with copies and then with a flyweight factory. Measure heap use with a profiler or Runtime.totalMemory.