Closed lboucin closed 11 months ago
Adding the following statement twin_model._tbroms = None
at the end of the loop solve the issue, see below:
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.
@chrpetre see proposed solution in PR #130
π Before submitting the issue
π Description of the bug
When instantiating a TwinModel in a loop, the allocated memory keep increasing.
π 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