UnmanageObject
UnmanageObject[man]
takes ownership of memory wrapped in a managed object.
Details
- man can be a ManagedObject or an object with the "Managed" type in compiled code.
- In compiled code, UnmanageObject has the type signature {"Managed"::[t]}t.
- UnmanageObject[man] mutably invalidates the managed object man. In compiled code, 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 allBasic Examples (2)
Unmanage it, returning the original wrapped value:
The managed object is no longer active:
Compile a function that creates a managed object:
Compile a function that unmanages the object:
Unmanage it, returning the original wrapped value:
Subsequent calls to UnmanageObject fail, as the managed object is invalidated when it is unmanaged:
Scope (3)
The freeing function is evaluated when the managed object is no longer referenced:
The freeing function is not evaluated if the managed object was 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:
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:
Properties & Relations (2)
Functions that allocate raw memory usually return a managed object:
Since the pointer is unmanaged, call RawMemoryFree when the memory is no longer used:
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:
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