Using Garbage Collection
❘
431
INTErAcTINg WITH THE INTErPrETEr AND ENvIroNmENT
The IronPython setup focuses more on .NET usage, rather than strict Python uses in some
respects. For example, IronPython doesn’t provide access to the Standard Library by default.
Chapter 6 explains techniques you can use to access the Standard Library and why this access is
important in some situations.
IronPython and CPython also behave differently in some situations. In some cases, this behavior is
by design or a necessity given the differing goals of the design teams. In other cases, the IronPython
team plans to fix the error or has asked the Python community about the issue and the Python com-
munity has found it acceptable. In fact, some of the following behavior issues might be fixed with
the next release of IronPython.
➤➤
The actual error output might not be changed in response to a change to
sys.stderror
.
IronPython and CPython use different forms of command line editing support.
➤
➤
➤
➤
IronPython and CPython use differing command line options, which means that batch files
created for one won’t necessarily work for the other.
➤
➤
Some
sys
module hooks may not work at all or may work differently than those in CPython.
For example, IronPython doesn’t implement the
sys.getrefcount()
method.
➤
➤
It’s possible to access
__dict__()
,
__module__()
,
__class__()
, and
__init__()
at the
global level, where CPython doesn’t allow global access.
uSINg gArBAgE collEcTIoN
CPython relies on an older method of keeping track of objects, reference counting, which is similar to
the technique used in older Component Object Model (COM) applications. IronPython uses a newer
garbage collector. Relying on a garbage collector is actually an advantage for the IronPython developer.
The Python community as a whole has decided that using a garbage collector is acceptable. However,
using a garbage collector has the following implications for the IronPython developer.
➤➤
No need to worry about circular references because the garbage collector ensures that such
instances are properly collected.
➤
➤
There’s no guarantee as to when finalization occurs or system resources are freed. This has
implications for people who constantly create and then free resources. The system could very
well slow down when garbage collection occurs at inconvenient times.
➤
➤
Invoking the
__del__()
method doesn’t immediately delete the affected resource. The dele-
tion occurs during the next garbage collection cycle.
➤
➤
Calling
sys.getrefcount()
returns an
AttributeError
because the
sys
module doesn’t
implement this feature.
➤
➤
CPython reuses
tuple
objects in some cases, but this behavior doesn’t occur in IronPython.
548592bapp01.indd 431
2/24/10 12:50:00 PM
www.finebook.ir
548592bapp01.indd 432
2/24/10 12:50:00 PM
www.finebook.ir
Do'stlaringiz bilan baham: |