Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak due to deepcopy ? #198

Open
raquelhortab opened this issue Apr 12, 2022 · 0 comments
Open

Possible memory leak due to deepcopy ? #198

raquelhortab opened this issue Apr 12, 2022 · 0 comments

Comments

@raquelhortab
Copy link

Hi, I am using a fair amount of trees (on some evolutionary computing task) and I find misself with some memory leak, I've traced the problem down to treelib's deepcopy. Is it possible that, when creating a Tree from another one (using the tree parameter and deep=True), it creates some link between the trees?

I perform loops on lists of trees, in each loop, I generate a new list and delete the previous one:

del list
gc.collect()

The new list is generated partially from trees from the previous list using Tree(tree=previous_tree, deep=True). The thing is that deleting the list does not free memory and my program's memory keeps increasing after each iteration. tracemalloc's stats suggest the problem is in treelib's deepcopy.

    child = TreeOperations.deep_copy(parent)
  File "/home/raquel/Documents/STUDIES/uned/uned/CE/A3/proj/trees.py", line 413
    tree = Tree(tree=a.tree, deep=True)
  File "/home/raquel/Documents/STUDIES/uned/uned/CE/venv/lib/python3.7/site-packages/treelib/tree.py", line 106
    new_node = deepcopy(node) if deep else node
  File "/usr/lib/python3.7/copy.py", line 180
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/python3.7/copy.py", line 281
    state = deepcopy(state, memo)
  File "/usr/lib/python3.7/copy.py", line 150
    y = copier(x, memo)
  File "/usr/lib/python3.7/copy.py", line 241
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.7/copy.py", line 180
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/python3.7/copy.py", line 307
    value = deepcopy(value, memo)
  File "/usr/lib/python3.7/copy.py", line 150
    y = copier(x, memo)
  File "/usr/lib/python3.7/copy.py", line 216
    append(deepcopy(a, memo))
  File "/usr/lib/python3.7/copy.py", line 169
    rv = reductor(4)
  File "/usr/lib/python3.7/uuid.py", line 208
    state = self.__dict__.copy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant