??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲欧洲美洲综合色网,国产成人综合精品三级,亚洲大全视频http://www.aygfsteel.com/yglwxl/category/39566.htmlzh-cnMon, 30 Nov 2009 11:11:11 GMTMon, 30 Nov 2009 11:11:11 GMT60How does Python manage memory?(http://docs.python.org/3.1/faq/design.html)http://www.aygfsteel.com/yglwxl/archive/2009/11/30/304232.html?ji)?/dc:creator>?ji)?/author>Mon, 30 Nov 2009 03:01:00 GMThttp://www.aygfsteel.com/yglwxl/archive/2009/11/30/304232.htmlhttp://www.aygfsteel.com/yglwxl/comments/304232.htmlhttp://www.aygfsteel.com/yglwxl/archive/2009/11/30/304232.html#Feedback0http://www.aygfsteel.com/yglwxl/comments/commentRss/304232.htmlhttp://www.aygfsteel.com/yglwxl/services/trackbacks/304232.htmlThe 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:
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:
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:
]]>Python 循环引用D内存泄漏的内存管理TEST ref fromQhttp://meizhini.javaeye.com/blog/249716http://www.aygfsteel.com/yglwxl/archive/2009/11/30/304229.html?ji)?/dc:creator>?ji)?/author>Mon, 30 Nov 2009 02:47:00 GMThttp://www.aygfsteel.com/yglwxl/archive/2009/11/30/304229.htmlhttp://www.aygfsteel.com/yglwxl/comments/304229.htmlhttp://www.aygfsteel.com/yglwxl/archive/2009/11/30/304229.html#Feedback0http://www.aygfsteel.com/yglwxl/comments/commentRss/304229.htmlhttp://www.aygfsteel.com/yglwxl/services/trackbacks/304229.html
因ؓ Python 有了自动垃圾回收功能Q不初学者就认ؓ自己从此q上了好日子Q不必再受内存泄漏的骚扰了。但如果查看一?Python 文?__del__() 函数的描qͼq道好日子里也是有阴云的。下面摘抄一Ҏ(gu)档内容:
Some common situations that may prevent the reference count of an object from going to zero include: circular references between objects (e.g., a doubly-linked list or a tree data structure with parent and child pointers); a reference to the object on the stack frame of a function that caught an exception (the traceback stored in sys.exc_traceback keeps the stack frame alive); or a reference to the object on the stack frame that raised an unhandled exception in interactive mode (the traceback stored in sys.last_traceback keeps the stack frame alive).
可见Q有 __del__() 函数的对象间的@环引用是D内存泄漏的主凶。特别说明:Ҏ(gu)?__del__() 函数?Python 对象间的循环引用Q是可以被自动垃圑֛收掉的?br />
]]>Python 块I间内存理TEST ref fromQ?http://www.javaeye.com/topic/309753http://www.aygfsteel.com/yglwxl/archive/2009/11/27/303916.html?ji)?/dc:creator>?ji)?/author>Fri, 27 Nov 2009 08:54:00 GMThttp://www.aygfsteel.com/yglwxl/archive/2009/11/27/303916.htmlhttp://www.aygfsteel.com/yglwxl/comments/303916.htmlhttp://www.aygfsteel.com/yglwxl/archive/2009/11/27/303916.html#Feedback1http://www.aygfsteel.com/yglwxl/comments/commentRss/303916.htmlhttp://www.aygfsteel.com/yglwxl/services/trackbacks/303916.htmldef test():
for i in range ( 1000000 * 10 ):
del i
if ( __name__ == "__main__" ):
test()
while ( True ):
time.sleep( 1 )
观察mem:内存l持不变!
我做q一个爬虫程?如果不断往q个U程里面传递url,那么q个U程不到一会就挂了.我的改进Ҏ(gu):是控制q线E能够接受的url队列长度.以及其他的优?
其实q个不是循环D的内存被python持有,而是range( n )让python分配了很多的内存.退出test(),python回收内存,但是pythonq不释放?而是让pool持有内存I间.