锘??xml version="1.0" encoding="utf-8" standalone="yes"?>在线电影你懂的亚洲,亚洲av成人中文无码专区,亚洲av无码成人精品国产
http://www.tkk7.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.tkk7.com/yglwxl/archive/2009/11/30/304232.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Mon, 30 Nov 2009 03:01:00 GMThttp://www.tkk7.com/yglwxl/archive/2009/11/30/304232.htmlhttp://www.tkk7.com/yglwxl/comments/304232.htmlhttp://www.tkk7.com/yglwxl/archive/2009/11/30/304232.html#Feedback0http://www.tkk7.com/yglwxl/comments/commentRss/304232.htmlhttp://www.tkk7.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 寰幆寮曠敤瀵艱嚧鍐呭瓨娉勬紡鐨勫唴瀛樼鐞員EST ref from錛歨ttp://meizhini.javaeye.com/blog/249716http://www.tkk7.com/yglwxl/archive/2009/11/30/304229.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Mon, 30 Nov 2009 02:47:00 GMThttp://www.tkk7.com/yglwxl/archive/2009/11/30/304229.htmlhttp://www.tkk7.com/yglwxl/comments/304229.htmlhttp://www.tkk7.com/yglwxl/archive/2009/11/30/304229.html#Feedback0http://www.tkk7.com/yglwxl/comments/commentRss/304229.htmlhttp://www.tkk7.com/yglwxl/services/trackbacks/304229.html
鍥犱負 Python 鏈変簡鑷姩鍨冨溇鍥炴敹鍔熻兘錛屼笉灝戝垵瀛﹁呭氨璁や負鑷繁浠庢榪囦笂浜嗗ソ鏃ュ瓙錛屼笉蹇呭啀鍙楀唴瀛樻硠婕忕殑楠氭壈浜嗐備絾濡傛灉鏌ョ湅涓涓?Python 鏂囨。瀵?__del__() 鍑芥暟鐨勬弿榪幫紝灝辯煡閬撳ソ鏃ュ瓙閲屼篃鏄湁闃翠簯鐨勩備笅闈㈡憳鎶勪竴鐐規(guī)枃妗e唴瀹癸細
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).
鍙錛屾湁 __del__() 鍑芥暟鐨勫璞¢棿鐨勫驚鐜紩鐢ㄦ槸瀵艱嚧鍐呭瓨娉勬紡鐨勪富鍑躲傜壒鍒鏄庯細瀵規(guī)病鏈?__del__() 鍑芥暟鐨?Python 瀵硅薄闂寸殑寰幆寮曠敤錛屾槸鍙互琚嚜鍔ㄥ瀮鍦懼洖鏀舵帀鐨勩?br />
]]>Python 灝忓潡絀洪棿鍐呭瓨綆$悊TEST ref from錛?http://www.javaeye.com/topic/309753http://www.tkk7.com/yglwxl/archive/2009/11/27/303916.html涔?jié)瀹?/dc:creator>涔?jié)瀹?/author>Fri, 27 Nov 2009 08:54:00 GMThttp://www.tkk7.com/yglwxl/archive/2009/11/27/303916.htmlhttp://www.tkk7.com/yglwxl/comments/303916.htmlhttp://www.tkk7.com/yglwxl/archive/2009/11/27/303916.html#Feedback1http://www.tkk7.com/yglwxl/comments/commentRss/303916.htmlhttp://www.tkk7.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:鍐呭瓨緇存寔涓嶅彉!
鎴戝仛榪囦竴涓埇铏▼搴?濡傛灉涓嶆柇寰榪欎釜綰跨▼閲岄潰浼犻抲rl,閭d箞榪欎釜綰跨▼涓嶅埌涓浼氬氨鎸備簡.鎴戠殑鏀硅繘鏂規(guī)硶:灝辨槸鎺у埗榪欑嚎紼嬭兘澶熸帴鍙楃殑url闃熷垪闀垮害.浠ュ強鍏朵粬鐨勪紭鍖?
鍏跺疄榪欎釜涓嶆槸寰幆瀵艱嚧鐨勫唴瀛樿python鎸佹湁,鑰屾槸range( n )璁﹑ython鍒嗛厤浜嗗緢澶氱殑鍐呭瓨.閫鍑簍est(),python鍥炴敹鍐呭瓨,浣嗘槸python騫朵笉閲婃斁浜?鑰屾槸璁﹑ool鎸佹湁鍐呭瓨絀洪棿.