In MicroPython though this doesn't seem to be the case. In MicroPython the __dict__ variable of an instance is still created. The memory savings associated with __slots__ comes from the fact that (in CPython) the __dict__ variable isn't created. Is there some way to realize the potential memory savings typically associated with __slots__ in MicroPython?
Code: Select all
class S(object): __slots__ = ['val'] def __init__(self, v): self.val = v x = S(42) print(x.val) x.new = "not possible"