11 Managing Memory Used by Objects

This chapter will explain a few important concepts of Python and OOP, such as the lifetime of an object (including deleting an object) and class variables, that didn’t fit well in the earlier chapters in this section. To tie all of this together, we’ll build a small game. I’ll also introduce slots, a memory management technique for objects. This chapter should give you a better understanding of how your code can affect the way that memory is used by objects.

Object Lifetime

In Chapter 2, I defined an object as “Data, plus code that acts on that data, over time.” I’ve talked quite a bit about data (instance ...

Get Object-Oriented Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.