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

TwinModel instance keep allocating memory when used in a loop #128

Closed
2 tasks done
lboucin opened this issue Nov 17, 2023 · 3 comments · Fixed by #134
Closed
2 tasks done

TwinModel instance keep allocating memory when used in a loop #128

lboucin opened this issue Nov 17, 2023 · 3 comments · Fixed by #134
Assignees
Labels
bug Something isn't working

Comments

@lboucin
Copy link
Collaborator

lboucin commented Nov 17, 2023

🔍 Before submitting the issue

  • I have searched among the existing issues
  • I am using a Python virtual environment

🐞 Description of the bug

When instantiating a TwinModel in a loop, the allocated memory keep increasing.

image

📝 Steps to reproduce

import os
import tracemalloc
from pytwin import TwinModel

tracemalloc.start()
snapshot = tracemalloc.take_snapshot()

twin_file = os.path.join("path_to_a_twin_model_with_tbrom.twin")
for i in range(1, 100):
twin_model = TwinModel(model_filepath=twin_file)
snapshot2 = tracemalloc.take_snapshot()
top_stats = snapshot2.compare_to(snapshot, 'lineno')
stat_tbrom_read_basis = top_stats[0]
print(stat_tbrom_read_basis)

💻 Which operating system are you using?

Windows

📀 Which ANSYS version are you using?

NA

🐍 Which Python version are you using?

3.9

📦 Installed packages

certifi==2023.7.22
charset-normalizer==3.3.2
colorama==0.4.6
coverage==7.3.2
cycler==0.11.0
exceptiongroup==1.1.3    
fonttools==4.38.0        
idna==3.4
imageio==2.31.2
iniconfig==2.0.0
kiwisolver==1.4.5        
matplotlib==3.5.3        
numpy==1.21.1
packaging==23.2
pandas==1.3.5
Pillow==9.5.0
platformdirs==4.0.0      
pluggy==1.3.0
pooch==1.8.0
pyparsing==3.1.1
pytest==7.4.3
pytest-cov==4.1.0
python-dateutil==2.8.2
-e git+https://github.com/ansys/pytwin@16cf78a84ed27a2881d0c7781a8afe66750a76e9#egg=pytwin
pytz==2023.3.post1
pyvista==0.38.6
pywin32==306
requests==2.31.0
scooby==0.7.3
six==1.16.0
tomli==2.0.1
tqdm==4.66.1
urllib3==2.0.7
vtk==9.3.0
@lboucin lboucin added the bug Something isn't working label Nov 17, 2023
@lboucin
Copy link
Collaborator Author

lboucin commented Nov 17, 2023

Adding the following statement twin_model._tbroms = None at the end of the loop solve the issue, see below:
image

@lboucin lboucin assigned lboucin and chrpetre and unassigned lboucin Nov 17, 2023
@lboucin
Copy link
Collaborator Author

lboucin commented Nov 20, 2023

Investigations: We are registering the __del__ method of the TwinModel with the atexit module in order to avoid the settings module tries to delete pytwin temp folder of the process before the log file of the TwinRuntime object owned by the TwinModel has been closed. This has a side effect which is that a TwinModel instance is referenced by the atexit module and thus preventing the garbage collector to collect and free the TwinModel at the end of the loop.

@lboucin
Copy link
Collaborator Author

lboucin commented Nov 20, 2023

@chrpetre see proposed solution in PR #130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants