Shapes object cannot be garbage collected

edited March 31 in Ruby Scripting

I use

shapes = layout.cell(cell_index).shapes(layer_info) 

and then call shapes.size() to get the number of shapes. This code runs well and quickly, but I have noticed that memory usage continues to rise. Using objgraph.show_most_common_types(), I found that the Shapes object remains in memory. Using objgraph.show_backrefs, I discovered that apart from gc.get_objects(), there are no other references. Similarly, I found that the q object inside for

 q in LayoutQuery("select cell_index, instances from cells *").each(layout)

has the same issue.I don't know how to resolve this issue, and I look forward to your response., thank you!

i sorry that it should be categorized under python scripting, but i made a mistake

Comments

  • Hi @nice,

    I understand you're talking Python here.

    I can reproduce the problem. I does not seem to have been introduced recently. The symptoms are the same for versions 0.28, 0.29 and 0.30 (Python 3.13). I have created a ticket for this here: https://github.com/KLayout/klayout/issues/2012. I will debug the issue.

    Lifetime management is difficult for some C++ side objects as they are bound in a loose way. Still, the should disappear when not needed any longer. Some caching is involved to avoid continuous generation of Python proxies. Maybe that is the problem here. And it wouldn't be for the first time that some Python evolution breaks original warranties.

    Thanks for reporting the problem.

    Matthias

  • I found a fix for the issue (see ticket on GitHub), but that needs some testing.

    Matthias

  • Thank you so much for fixing the bug — I really appreciate your help! I'd love to contribute in any way I can to help make the project even better.

  • Hi @nice - I actually have to thank you!

    This was an important observation and I appreciate your efforts in debugging the problem. Fixing this issue will help many others too and to me that is the Open Source spirit. So this was already an significant contribution from your side :)

    Best regards,

    Matthias

Sign In or Register to comment.