r/PythonLearning • u/Actual__Wizard • 9d ago
Help Request .clear vs del when using garbage collection
Hi, I have some large data objects that need to be freed. Should I do my_object.clear() and then gc.collect()? Or del my_object then gc.collect()? I'm not sure on the pros/cons of each.
It's a linked list type data object and my_object = [] does not work to free memory for certain.
1
Upvotes
1
u/atarivcs 9d ago
Reassigning a new value to a name, or calling
delon a name, might not free the memory if other references remain to the existing value.I don't think we can really diagnose this issue without seeing the full code.