MATLAB: How does SimBiology 3.1 (R2009b) handle memory management when passing a simbio model object to a function that modifies it and then returns it

SimBiology

I would like to know whether a copy of the model is created in the called function, modifications are made, and then the original model is overwritten upon returning. Or whether the model is passed by reference and all modifications made on the original model directly.

Best Answer

SimBiology 3.1 (R2009b) models are handle objects, which means that they are passed by reference. Therefore, any changes made to a model will be visible to everyone who has that handle. Unlike some other MATLAB handle objects, all SimBiology models automatically have a handle added to the SimBiology root object. This prevents the user from losing a model by clearing or overwriting a variable. However, this does highlight an important consideration for memory management: to remove a SimBiology model from memory, it must be explicitly deleted with a command like
delete(m1)
All SimBiology models in memory can also be deleted at once by using the function SBIORESET.