[Python] Where to call gc.collect()

Discussão em 'Python' iniciado por Stack, Julho 12, 2025.

  1. Stack

    Stack Membro Participativo

    Where should I call garbage collector? Will calling it after a function has been called clear the memory of the called function?

    Also what is the difference between calling gc.collect() and specifically doing del on a variable

    def a():
    b()
    # should I call gc.collect() here?
    # is there any other way to release memory allocated in the called function here?

    def b():
    # big allocation like
    foo = ['abc' for x in range(10**7)]

    # should I call gc.collect() here?
    # should I do a foo = None and x = None here?

    Continue reading...

Compartilhe esta Página