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

Memory increases when creating and destroying the FieldsBuilder repeatedly #7242

Open
lin-hitonami opened this issue Jan 28, 2023 · 1 comment
Assignees

Comments

@lin-hitonami
Copy link
Contributor

lin-hitonami commented Jan 28, 2023

Describe the bug
The memory increases when running the snippet below by ~5KB/iter.
From https://forum.taichi-lang.cn/t/topic/3839
To Reproduce

import taichi as ti
ti.init()

def w():
     i = 0
     while i < 1000000:
         particle_per_cell = 1000000
         num_particle_in_cell = ti.field(int)
         fb1 = ti.FieldsBuilder()
         fb1.dense(ti.i, particle_per_cell).place(num_particle_in_cell)
         fb1_snode_tree = fb1.finalize()
         fb1_snode_tree.destroy()
w()
@github-project-automation github-project-automation bot moved this to Untriaged in Taichi Lang Jan 28, 2023
@lin-hitonami lin-hitonami moved this from Untriaged to Todo in Taichi Lang Feb 3, 2023
@feisuzhu feisuzhu assigned jim19930609 and unassigned bobcao3 Mar 17, 2023
@jim19930609
Copy link
Contributor

For this specific issue, the memory leak comes from pytaichi.global_vars which holds a expr_field corresponding to the place-SNode of the field. Upon SNodeTree destruction, the cached expr_field won't get poped from the global_vars, resulting in the memory leak.

截图 2023-04-03 14-07-34

The bigger issue is that there's no lifetime management for the global variables associated with PyTaichi, therefore similar memory leak will still appear if we only fix this single issue. I'd suggest fixing this PR along with the Type System Refactor, where we can implement a more systematic mechanism to manage the global variables & caches at Python scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

3 participants