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.
Examplesopen allclose all
Basic Examples (2)
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, https://reference.wolfram.com/language/ref/CreateManagedObject.html.
Wolfram Language. 2023. "CreateManagedObject." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CreateManagedObject.html.
Wolfram Language. (2023). CreateManagedObject. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CreateManagedObject.html