creates a managed object that evaluates f[expr] when it is no longer referenced.


  • Many functions that expect pointer objects will automatically unwrap managed expressions containing pointers.
  • CreateManagedObject[expr,man] creates a new managed object representing expr, which shares a reference count with the ManagedObject man.
  • Only active managed objects evaluate the freeing function when they are no longer referenced.
  • Managed objects can be inactivated with UnmanageObject.


open allclose all

Basic Examples  (2)

Create a managed object:

Get the contained expression:

f[expr] is evaluated once the managed object is no longer referenced:

Possible Issues  (3)

Managed objects are often freed too soon when using With, where the reference count is decremented after the last use of the symbol in the body:

Module can be used instead, which only decrements the reference count at the end:

func[expr] is evaluated once the reference count of the managed expression object is zero. However, expr may exist outside of the managed expression, allowing it to continue even after its reference count is nominally zero:

There are many cases where the reference count would seem to be zero, but where it is not because of Out:

Access the managed object with Out:

Wolfram Research (2023), CreateManagedObject, Wolfram Language function,


Wolfram Research (2023), CreateManagedObject, Wolfram Language function,


Wolfram Language. 2023. "CreateManagedObject." Wolfram Language & System Documentation Center. Wolfram Research.


Wolfram Language. (2023). CreateManagedObject. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2023_createmanagedobject, author="Wolfram Research", title="{CreateManagedObject}", year="2023", howpublished="\url{}", note=[Accessed: 02-December-2023 ]}


@online{reference.wolfram_2023_createmanagedobject, organization={Wolfram Research}, title={CreateManagedObject}, year={2023}, url={}, note=[Accessed: 02-December-2023 ]}