1

Assume I have these lines of code :

class Ab:
   def __init__(self):
      self.x = [i for i in range(1000)]

AbList = [Ab() for i in range(1000)]

for i in range(500):
   AbList.pop()

Will python free up my memory after I popped the objects?

  • 2
    Yes. After you call `pop`, `AbList` won't maintain a reference to the `Ab` instances (and their `x` members). Eventually (i.e., milliseconds to several seconds), the garbage collector will free the memory associated with these objects. You can use a process manager or `top`, do the `pop`, and then force garbage collection with `import gc ; gc.collect()` to observe this for yourself. – wildwilhelm Jan 20 '17 at 13:10

1 Answers1

1

Python has a garbage collector that will free this memory after you'll delete the objects

limitless
  • 669
  • 7
  • 18