<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    常用鏈接

    統(tǒng)計(jì)

    最新評(píng)論

    How does Python manage memory?(http://docs.python.org/3.1/faq/design.html)

    The details of Python memory management depend on the implementation. The standard C implementation of Python uses reference counting to detect inaccessible objects, and another mechanism to collect reference cycles, periodically executing a cycle detection algorithm which looks for inaccessible cycles and deletes the objects involved. The gc module provides functions to perform a garbage collection, obtain debugging statistics, and tune the collector’s parameters.

    Jython relies on the Java runtime so the JVM’s garbage collector is used. This difference can cause some subtle porting problems if your Python code depends on the behavior of the reference counting implementation.

    Sometimes objects get stuck in tracebacks temporarily and hence are not deallocated when you might expect. Clear the tracebacks with:

    import sys
    sys.exc_clear()
    sys.exc_traceback = sys.last_traceback = None
    

    Tracebacks are used for reporting errors, implementing debuggers and related things. They contain a portion of the program state extracted during the handling of an exception (usually the most recent exception).

    In the absence of circularities and tracebacks, Python programs need not explicitly manage memory.

    Why doesn’t Python use a more traditional garbage collection scheme? For one thing, this is not a C standard feature and hence it’s not portable. (Yes, we know about the Boehm GC library. It has bits of assembler code for most common platforms, not for all of them, and although it is mostly transparent, it isn’t completely transparent; patches are required to get Python to work with it.)

    Traditional GC also becomes a problem when Python is embedded into other applications. While in a standalone Python it’s fine to replace the standard malloc() and free() with versions provided by the GC library, an application embedding Python may want to have its own substitute for malloc() and free(), and may not want Python’s. Right now, Python works with anything that implements malloc() and free() properly.

    In Jython, the following code (which is fine in CPython) will probably run out of file descriptors long before it runs out of memory:

    for file in <very long list of files>:
    f = open(file)
    c = f.read(1)
    

    Using the current reference counting and destructor scheme, each new assignment to f closes the previous file. Using GC, this is not guaranteed. If you want to write code that will work with any Python implementation, you should explicitly close the file; this will work regardless of GC:

    for file in <very long list of files>:
    f = open(file)
    c = f.read(1)
    f.close()
    

    posted on 2009-11-30 11:01 九寶 閱讀(286) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Python

    主站蜘蛛池模板: 亚洲卡一卡2卡三卡4麻豆| 亚洲AV无码专区电影在线观看 | 妞干网手机免费视频| 亚洲理论片在线中文字幕| 久久久久久久岛国免费播放| 亚洲人成电影在在线观看网色| 黄页免费在线观看| 久久综合亚洲色HEZYO社区| 一级毛片全部免费播放| 91亚洲一区二区在线观看不卡| 99re这里有免费视频精品| 亚洲色图.com| 成人性生交大片免费看无遮挡| 亚洲av永久无码精品秋霞电影秋 | 亚洲国产成人久久精品动漫 | 久久精品免费观看| 久久综合亚洲鲁鲁五月天| 久久久久久久91精品免费观看| 国产亚洲精品VA片在线播放| 日日AV拍夜夜添久久免费| 十八禁的黄污污免费网站| 亚洲一区二区三区香蕉| 日本h在线精品免费观看| 亚洲国产视频久久| www国产亚洲精品久久久| 一个人免费视频在线观看www | 亚洲午夜成人精品无码色欲| 免费看国产精品麻豆| 91在线视频免费观看| 亚洲国产综合第一精品小说| 成人au免费视频影院| a一级毛片免费高清在线| 亚洲第一精品在线视频| 四虎www成人影院免费观看| 国产日韩久久免费影院| 亚洲电影免费观看| 免费大片在线观看网站| 99精品热线在线观看免费视频| 亚洲s码欧洲m码吹潮| 国产V亚洲V天堂A无码| 成人免费午间影院在线观看|