---
title: "JSValueProtect(_:_:)"
framework: javascriptcore
role: symbol
role_heading: Function
path: "javascriptcore/jsvalueprotect(_:_:)"
---

# JSValueProtect(_:_:)

Protects a JavaScript value from garbage collection.

## Declaration

```swift
func JSValueProtect(_ ctx: JSContextRef!, _ value: JSValueRef!)
```

## Parameters

- `ctx`: The execution context to use.
- `value`: The doc://com.apple.javascriptcore/documentation/JavaScriptCore/JSValueRef to protect.

## Discussion

Discussion Use this method when you want to store a JSValueRef in a global or on the heap, where the garbage collector can’t discover your reference to it. You can protect a value multiple times and must unprotect it an equal number of times before it becomes eligible for garbage collection.

## See Also

### Supporting Garbage Collection

- [JSValueUnprotect(_:_:)](javascriptcore/jsvalueunprotect(_:_:).md)
