---
title: JSManagedValue
framework: javascriptcore
role: symbol
role_heading: Class
path: javascriptcore/jsmanagedvalue
---

# JSManagedValue

A JavaScript value with conditional retain behavior to provide automatic memory management.

## Declaration

```swift
class JSManagedValue
```

## Overview

Overview The primary use case for a managed value is to store a JavaScript value in an Objective-C or Swift object that exports to JavaScript. important: Don’t store a nonmanaged JSValue object in a native object that exports to JavaScript. Because a JSValue object references its enclosing JSContext object, this action creates a retain cycle, preventing deallocation of the context. A managed value’s conditional retain behavior ensures retention of its underlying JavaScript value 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 you report to the JavaScriptCore virtual machine using the addManagedReference(_:withOwner:) method. However, if neither of these conditions is true, the managed value sets its value property to nil, releasing the underlying JSValue object. note: On its own, a JSManagedValue object behaves similarly to an ARC weak reference to its underlying JSValue object—that is, if you don’t use the addManagedReference(_:withOwner:) method to add conditional retain behavior, the managed value’s value property automatically becomes nil when the JavaScript garbage collector destroys the underlying JavaScript value.

## Topics

### Creating a Managed Value

- [init(value:)](javascriptcore/jsmanagedvalue/init(value:).md)
- [init(value:andOwner:)](javascriptcore/jsmanagedvalue/init(value:andowner:).md)

### Accessing the Managed Value

- [value](javascriptcore/jsmanagedvalue/value.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### JavaScript Code

- [JSValue](javascriptcore/jsvalue.md)
