Question About When Objects Are Destroyed (continued)
Tim Daneliuk <info at tundraware.com>:
> On 08/04/2017 07:00 PM, Chris Angelico wrote:
>> Again, don't stress about exactly when objects get disposed of; it
>> doesn't matter.
> Respectfully, I disagree strongly. Objects get build on the heap and
> persist even when they go out of scope until such time garbage
> collection takes place. This is unlike languages that build things in
> stack frames which naturally disappear with an exit of scope.
Python never has to dispose of a single object. It is allowed to do so
if it doesn't affect the correct behavior of the program.
> For small or trivial programs, it does not matter. But when there is a
> lot of dynamic object construction - say, in very large programs,
> object factories, etc. - it can be important to harvest the space of
> expired objects sooner, rather than later. This, after all, is one of
> the rationale' for Python contexts - to ensure the release of
> resources no matter how the logic ends - correctly or by exception.
You are correct that maintaining references to stale objects prevents
Python's garbage collection from reclaiming memory space.
Releasing non-memory resources is a different matter. I suppose Chris
was only referring to RAM usage.