creates a managed library expression by applying f to a positive integer ID associated with a registered manager with name mname.


  • The IDs generated for the manager with name mname start at 1 and follow sequentially until the manager is unregistered.
  • A manager is registered by using the LibraryLink callback function registerLibraryExpressionManager.


Basic Examples  (1)

Load example LibraryFunction objects that implement a simple linear congruential random generator:

Create an instance of a linear congruential generator:

Set its parameters using the unique ID assigned by CreateManagedLibraryExpression:

Generate two pseudorandom numbers from the instance:

Set up another instance and generate three numbers from it:

The first instance is available until the expression is no longer referenced:

The history expression Out will often keep references to an expression you may not be aware of. Extra references like this can be prevented by setting $HistoryLength=0 either in a session or inside of Block:

The variable g3 is the only reference to the managed library instance, so when g3 is unset, the library instance is freed and expressions with this ID will no longer work:

Note that the same does not work for g1 because it is referenced by Out:

Wolfram Research (2014), CreateManagedLibraryExpression, Wolfram Language function,


Wolfram Research (2014), CreateManagedLibraryExpression, Wolfram Language function,


Wolfram Language. 2014. "CreateManagedLibraryExpression." Wolfram Language & System Documentation Center. Wolfram Research.


Wolfram Language. (2014). CreateManagedLibraryExpression. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2024_createmanagedlibraryexpression, author="Wolfram Research", title="{CreateManagedLibraryExpression}", year="2014", howpublished="\url{}", note=[Accessed: 24-June-2024 ]}


@online{reference.wolfram_2024_createmanagedlibraryexpression, organization={Wolfram Research}, title={CreateManagedLibraryExpression}, year={2014}, url={}, note=[Accessed: 24-June-2024 ]}