WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

CreateManagedObject [expr,f]

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

Details
Details and Options Details and Options
Examples  
Basic Examples  
Possible Issues  
See Also
Tech Notes
Related Guides
History
Cite this Page

CreateManagedObject [expr,f]

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

Details

  • 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 .

Examples

open all close all

Basic Examples  (2)

Create a managed object:

Wolfram Language code: man = CreateManagedObject[foo, Echo]

Get the contained expression:

Wolfram Language code: man["Value"]

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

Wolfram Language code: With[{man = CreateManagedObject[foo, Echo]}, Null]

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:

Wolfram Language code: With[{man = CreateManagedObject[foo, Echo["freed"]&]}, EchoLabel["func"][man["Value"]] ]

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

Wolfram Language code: Module[{man = CreateManagedObject[foo, Echo["freed"]&]}, EchoLabel["func"][man["Value"]] ]

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:

Wolfram Language code: With[{man = CreateManagedObject[foo, Echo]}, man["Value"]]

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

Wolfram Language code: CreateManagedObject[foo, Echo];

Access the managed object with Out :

Wolfram Language code: %

Tech Notes

Wolfram Research (2023), CreateManagedObject, Wolfram Language function, https://reference.wolfram.com/language/ref/CreateManagedObject.html.

Text

Wolfram Research (2023), CreateManagedObject, Wolfram Language function, https://reference.wolfram.com/language/ref/CreateManagedObject.html.

CMS

Wolfram Language. 2023. "CreateManagedObject." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CreateManagedObject.html.

APA

Wolfram Language. (2023). CreateManagedObject. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CreateManagedObject.html

BibTeX

@misc{reference.wolfram_2026_createmanagedobject, author="Wolfram Research", title="{CreateManagedObject}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/CreateManagedObject.html}", note=[Accessed: 14-August-2026]}

BibLaTeX

@online{reference.wolfram_2026_createmanagedobject, organization={Wolfram Research}, title={CreateManagedObject}, year={2023}, url={https://reference.wolfram.com/language/ref/CreateManagedObject.html}, note=[Accessed: 14-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /