Slots to Save Memory

Talk it through out loud with your AI coach.

The problem

  • medium
  • Pro

A data processing job creates tens of millions of small Point objects with x and y attributes and runs out of memory. A colleague suggests adding slots to the class. Explain what slots do, how much they help, and the trade-offs.

What a strong answer covers

  • Where ordinary instances keep their attributes and what that costs.
  • What declaring slots changes about each object.
  • What you give up, including with inheritance.
  • Other tools for very large numbers of small records.

Common mistake: Measuring the saving with a single size check on one object, which doesn't count the attribute dictionary at all.

Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.

Practise it out loud