相关疑难解决方法(0)

Python垃圾收集器文档

我正在寻找详细描述python垃圾收集如何工作的文档.

我很感兴趣在哪一步做了什么.这三个系列中有哪些对象?每个步骤中删除了哪些对象?什么算法用于参考循环发现?

背景:我正在实施一些必须在很短的时间内完成的搜索.当垃圾收集器开始收集最老的一代时,它比其他情况"慢得多".花了比搜索更多的时间.我正在寻找如何预测它将收集最老一代的时间以及需要多长时间.

这是很容易预测它什么时候会收集最古老的一代与get_count()get_threshold().这也可以用set_threshold().但是,我不认为collect()通过武力或等待预定的收集更好地决定是否更好.

python garbage-collection

130
推荐指数
1
解决办法
8万
查看次数

当变量超出范围时,Python 不会删除变量

考虑以下代码:

import random                                                                   

class Trie:                                                                     
    def __init__(self, children, end):                                          
        self.children = children                                                
        self.end = end                                                          

def trie_empty():                                                               
    return Trie(dict(), False)                                                  

def trie_insert(x, t):                                                          
    if not x:                                                                   
        t.end = True                                                            
        return                                                                  
    try:                                                                        
        t2 = t.children[x[0]]                                                   
    except KeyError:                                                            
        t2 = trie_empty()                                                       
        t.children[x[0]] = t2                                                     
    trie_insert(x[1:], t2)                                                      

def fill_dict(root):                                                            
    memo = dict()                                                               
    def fill(pfx='', depth=0):                                                  
        try:                                                                    
            memo[pfx]                                                           
        except KeyError:                                                        
            pass                                                                
        else:                                                                   
            return                                                              
        if depth > 6:                                                           
            return                                                              
        for ci in range(ord('a'), ord('d') + 1):                                
            fill(pfx + chr(ci), depth + 1)                                      
        bw = None …
Run Code Online (Sandbox Code Playgroud)

python

1
推荐指数
1
解决办法
984
查看次数

标签 统计

python ×2

garbage-collection ×1