[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question About When Objects Are Destroyed (continued)

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.

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.