gc

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package gc ports the refcount-only path of cpython/Python/gc.c. v0.3 ships Track, Untrack, RegisterFinalizer, and Finalize. Cycle collection is a no-op until v0.10 lands the cycle collector.

CPython: Python/gc.c file overview

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect() int

Collect runs the cycle collector. v0.3 has none, so this returns 0. The signature is preserved so callers compile against v0.10 without changes.

CPython: Modules/gcmodule.c:L1430 gc_collect_main

func Finalize

func Finalize(o objects.Object)

Finalize runs the finalizer for o exactly once and clears it. Safe to call on objects that never registered one. Mirrors PyObject_CallFinalizerFromDealloc.

CPython: Objects/object.c:L497 PyObject_CallFinalizerFromDealloc

func IsTracked

func IsTracked(o objects.Object) bool

IsTracked reports whether o is currently tracked.

CPython: Include/internal/pycore_object.h:L268 _PyObject_GC_IS_TRACKED

func RegisterFinalizer

func RegisterFinalizer(o objects.Object, fn Finalizer)

RegisterFinalizer associates fn with o. The runtime calls Finalize to invoke it. Mirrors PyObject_GC_RegisterFinalizer in spirit; in CPython the per-object slot is tp_finalize, but gopy keeps the mapping out-of-band so Header stays small.

CPython: Objects/object.c:L489 PyObject_CallFinalizer (caller side)

func Track

func Track(o objects.Object)

Track adds o to the tracked-object set. Cycle collection (v0.10) will walk this set; for now it is bookkeeping only.

CPython: Modules/gcmodule.c:L2178 PyObject_GC_Track

func Untrack

func Untrack(o objects.Object)

Untrack removes o from the tracked-object set. No-op if not tracked.

CPython: Modules/gcmodule.c:L2200 PyObject_GC_UnTrack

Types

type Finalizer

type Finalizer func(o objects.Object)

Finalizer is the Go equivalent of tp_finalize. The runtime invokes it once, immediately before reclaiming the object.

CPython: Include/cpython/object.h:L237 tp_finalize

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL