UnmanageObject

UnmanageObject[man]

takes ownership of memory wrapped in a "Managed" object, suitable for use in compiled code.

Details

  • UnmanageObject is only available in compiled code.
  • UnmanageObject has the type signature {"Managed"::[t]}t.
  • UnmanageObject[man] mutably invalidates the "Managed" object man. Reusing man after it has been invalidated is a runtime error.
  • UnmanageObject can be used when passing an object to external code that will hold a long-term reference to it.

Examples

open allclose all

Basic Examples  (2)

Compile a function that creates a managed object:

Compile a function that unmanages the object:

Create a managed object:

Unmanage it, returning the original wrapped value:

Subsequent calls to UnmanageObject fail, as the managed object is invalidated when it is unmanaged:

Managed objects are invalidated by UnmanageObject and are not freed when they go out of scope. Compile functions for creating an unmanaged object:

Create a managed object and then let it pass out of scope:

Unmanage the object before letting it pass out of scope:

Scope  (1)

The contents of managed objects can effectively be borrowed by unmanaging them and then creating a new managed object. Compile a function for creating a managed C array:

Compile a function that unmanages, modifies and then remanages the C array:

Create a managed C array:

Modify it, returning a new managed C array:

Properties & Relations  (1)

Managed objects are automatically unwrapped by functions declared with LibraryFunctionDeclaration, so no calls to UnmanageObject are needed:

The managed C array is borrowed and automatically unwrapped before it is passed to the library function:

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

Text

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

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2022_unmanageobject, author="Wolfram Research", title="{UnmanageObject}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/UnmanageObject.html}", note=[Accessed: 28-November-2022 ]}

BibLaTeX

@online{reference.wolfram_2022_unmanageobject, organization={Wolfram Research}, title={UnmanageObject}, year={2022}, url={https://reference.wolfram.com/language/ref/UnmanageObject.html}, note=[Accessed: 28-November-2022 ]}