---
title: "finalizer-captures-object"
description: "Detect finalizers that retain the object they should release."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# finalizer-captures-object

**Default severity:** `error`

A finalizer closure that captures the finalized object keeps that object
reachable. The garbage collector can never make the object eligible for
finalization, so the finalizer never runs and the object leaks.

Use the finalizer function's parameter to operate on the object instead of
capturing the outer variable.

## Bad

```go
runtime.SetFinalizer(object, func(*resource) { object.Close() })
```

## Good

```go
runtime.SetFinalizer(object, func(object *resource) { object.Close() })
```

Source: https://strider.gempir.com/analyzers/finalizer-captures-object/index.mdx
