Oliver Schoenborn wrote: >>Python does provide finalization, and in a reliable way: the finalizer >>is called before the object goes away, guaranteed. > > > The python docs are a bit confusing to me in this regard, so allow me to > quote a few section: > > From Python 2.3 docs: > > "An implementation is allowed to postpone garbage collection > or omit it altogether -- it is a matter of implementation > quality how garbage collection is implemented, as long as no > objects are collected that are still reachable. This is precisely what I said: the object is finalized before it goes away. If it does not go away, it might not get finalized. > So it seems that having a __del__ is ok *most* of the time, and that if you > find a mem leak, verify if you have cyclical refs, and modify algorithm to > break cycle because gc won't be able to call __del__; however if an > exception gets thrown, you can't rely on __del__ getting called. Since > exceptions are so common, I have to conclude that you can never rely on > __del__ to free resources. Where am I wrong in this reasoning? Yes, you are wrong. The Python language specification does not make guarantees. However, specific implementations do make specific guarantees beyond what the language specification guarantees. Your proposed mechanism cannot be added to the Python language specification because there might be Python implementations for which the mechanism is difficult to implement. Regards, Martin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4