You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Referring to tables in TableCollection leaks memory #2428
It seems like there must be some circular references down in where we do the allocation of the Table instances. It's all quite complicated and twisty down there though, so I'm at a bit of a loss as to what's going on here.
It seems this is partially at least because of how we're doing metadata decoding. If I run the code accessing ts.tables.sites above (and therefore creating a new instance of SiteTable each time because of #2080) then we get memory usage going up to 1GB like above. However, if I comment out this line here:
Usage goes down to a nice flat 60MiB. So it seems like we've created a circular reference of some sort by wrapping the row_class, and so we leak some memory every time we access one of the tables.
Activity
jeromekelleher commentedon Jul 21, 2022
TODO: add some reproducible example here using mprof
jeromekelleher commentedon Jul 21, 2022
Let's mimic the memory leak we see in
ts.site(position=x)by accessing the relevant bits of the tables in a loop:First, just accessing
ts.tableslike here:As it should be
jeromekelleher commentedon Jul 21, 2022
Now, change it around so we do
pos=ts.tables.sites.position:We're using waaaaay more memory, and it looks like garbage collection isn't recovering it all.
jeromekelleher commentedon Jul 21, 2022
Accessing
ts.tables.sitesgives us:🤔
jeromekelleher commentedon Jul 21, 2022
It seems like there must be some circular references down in where we do the allocation of the Table instances. It's all quite complicated and twisty down there though, so I'm at a bit of a loss as to what's going on here.
molpopgen commentedon Jul 21, 2022
We've got a couple of these piling up. Relevant to tskit-dev/msprime#1946?
jeromekelleher commentedon Jul 22, 2022
Yep, that's probably the same thing, thanks @molpopgen
jeromekelleher commentedon Jul 22, 2022
Note: #2080 is relevant here, because we create a new instance of the high-level table class each time
tables.nodesis accessed.jeromekelleher commentedon Jul 22, 2022
It seems this is partially at least because of how we're doing metadata decoding. If I run the code accessing
ts.tables.sitesabove (and therefore creating a new instance of SiteTable each time because of #2080) then we get memory usage going up to 1GB like above. However, if I comment out this line here:tskit/python/tskit/tables.py
Line 721 in c12c160
Usage goes down to a nice flat 60MiB. So it seems like we've created a circular reference of some sort by wrapping the row_class, and so we leak some memory every time we access one of the tables.
[-]ts.tables leaks memory[/-][+]Referring to tables in TableCollection leaks memory[/+]Fix memory leak in table references.
Fix memory leak in table references.
Fix memory leak in table references.
Fix memory leak in table references.
Fix memory leak in table references.