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

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

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

    常用鏈接

    統(tǒ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) 評論(0)  編輯  收藏 所屬分類: Python

    主站蜘蛛池模板: 亚洲一区综合在线播放| 日韩免费高清视频网站| 久久91亚洲精品中文字幕| 国产精品九九久久免费视频 | 成人免费视频69| 亚洲va在线va天堂va四虎 | 97视频热人人精品免费| 亚洲中文字幕在线无码一区二区 | 久久精品免费视频观看| 亚洲成年轻人电影网站www | 亚洲国产精品张柏芝在线观看| 最近免费中文字幕大全免费版视频| 免费AA片少妇人AA片直播| 亚洲国产中文在线二区三区免| 最新欧洲大片免费在线| 亚洲欧美日韩中文二区| 亚洲成人国产精品| 激情综合亚洲色婷婷五月| 成人av免费电影| 免费一级特黄特色大片| 亚洲精品成人片在线播放 | 免费的黄色的网站| 亚洲日韩乱码中文无码蜜桃臀网站| 日本黄色动图免费在线观看| 亚洲成人黄色网址| 国产资源免费观看| 99视频在线免费观看| 亚洲一级免费视频| 亚洲精品麻豆av| **一级毛片免费完整视| 亚洲综合在线视频| 日本免费一区二区三区最新| 精品97国产免费人成视频| 亚洲美女视频网址| 污污网站18禁在线永久免费观看| 亚洲成a人片在线观看国产| 日本不卡免费新一区二区三区| 亚洲日本乱码卡2卡3卡新区| 国产成人精品久久亚洲高清不卡 | 福利片免费一区二区三区| 久久国产精品亚洲综合|