<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSVirtualMachine/addManagedReference(_:withOwner:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:objc(cs)JSVirtualMachine(im)addManagedReference:withOwner:"
  },
  "title" : "addManagedReference(_:withOwner:)"
}
-->

# addManagedReference(_:withOwner:)

Notifies the JavaScriptCore virtual machine of an external object relationship.

```
func addManagedReference(_ object: Any!, withOwner owner: Any!)
```

## Parameters

`object`

The object to be referenced by the JavaScript memory management graph.

`owner`

The other object responsible for the lifetime of the reference.

## Discussion

Use this method to make the JavaScript runtime aware of arbitrary external Objective-C or Swift object graphs. The runtime can then use this information to retain any JavaScript values that are referenced from somewhere in said object graph.

For correct behavior, clients must make their external object graphs reachable from within the JavaScript runtime. If an Objective-C or Swift object is reachable from within the JavaScript runtime, all managed references transitively reachable from it as recorded using the [`addManagedReference(_:withOwner:)`](/documentation/JavaScriptCore/JSVirtualMachine/addManagedReference(_:withOwner:)) method are scanned by the garbage collector.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)