sbiosimulate Not Releasing Memory

3 views (last 30 days)
Rae.K
Rae.K on 3 Nov 2022
Commented: Rae.K on 3 Nov 2022
I have a somewhat large model, that I am simulating (repeatedly with slight variations of the parameters) in Simbiology, that is consistently resulting in "Out of Memory" errors.
I can see with the `memory` command when I run the line:
simData = sbiosimulate(virtualPatientModel,configSettings,doses)
that the "Memory used by MATLAB" jumps about 4GB with each iteration (so it doesn't get through many iterations).
If I run clear simData the memory is not released (though the variable is removed from the workspace). If I run clear all the memory is not released.
Setting the number of output times to reasonably small, and logging only 2 species does not reduce the additional memory used with each iteration.
If I assign a variable to every property of simData, I can see with the whos command that none of them are using much memory (KBs at most).
So I'm confused about what is actually using the memory and how to release it.
This behavior is consistent in R2022a and R2020b, with sundials and ode23t. (The integration is extremely slow with ode45 and ode15s).
Unfortunately I cannot share this model because both the structure and the parameters are proprietary, and I have been unsuccessful in making a minimal working example. (Clearing simData releases the memory as expected in the smaller model, and reducing the output times reduces the memory accumulated with each iteration.)
What is causing this? How do I diagnose or fix it?

Accepted Answer

Arthur Goldsipe
Arthur Goldsipe on 3 Nov 2022
My guess is that this memory usage is somehow associated with SimBiology models that are still in memory. If you want to reclaim memory associated with a SimBiology model you must explicitly call delete on that model, for example delete(virtualPatientModel). If each iteration creates a new model without deleting any models, that could very well explain the memory usage. You see all the models that are still in memory by calling sbioroot and looking at the Models property. You can access these models and delete them via this property. You can also call sbioreset to delete all models that are in memory.
If that doesn't solve your problem, then my suggestion would be to contact technical support, especially if you are comfortable sharing reproduction steps with them. We can also potentially help you "obfuscate" the details of any model before you share it.
If you can't share the actual model, can you share the code that does the iteration? That might give us some insight into what is using memory. It might also help to know more about how many species, parameters, reactions, and such are in your model. And how many time points are logged in each simulation.
I hope that gives you some ideas that help.
-Arthur
  1 Comment
Rae.K
Rae.K on 3 Nov 2022
Thank you, Arthur! This is just what I needed.

Sign in to comment.

More Answers (0)

Communities

More Answers in the  SimBiology Community

Categories

Find more on Scan Parameter Ranges in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!