A JSManagedValue object wraps a JSValue object, adding “conditional retain” behavior to provide automatic memory management of values. The primary use case for a managed value is to store a JavaScript value in an Objective-C or Swift object that is itself exported to JavaScript.


class JSManagedValue : NSObject


A managed value’s “conditional retain” behavior ensures that its underlying JavaScript value is retained as long as either of the following conditions is true:

  • The JavaScript value is reachable through the JavaScript object graph (that is, not subject to JavaScript garbage collection)

  • The JSManagedValue object is reachable through the Objective-C or Swift object graph, as reported to the JavaScriptCore virtual machine using the addManagedReference(_:withOwner:) method

However, if neither of these conditions are true, the managed value sets its value property to nil, releasing the underlying JSValue object.


Creating a Managed Value

init!(value: JSValue!)

Initializes a managed value with the specified JavaScript value.

init!(value: JSValue!, andOwner: Any!)

Creates a managed value and associates it with an owner.

Accessing the Managed Value

var value: JSValue!

The managed value’s underlying JavaScript value.


Inherits From

Conforms To

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software