objref

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Rendered for darwin/amd64

Overview

Package objref stores the Objective-C object pointer that sits behind each Go wrapper type, and lets the generated packages read one another's pointers internally — without that pointer ever appearing in a public function signature.

Every generated wrapper type (for example a String or a VirtualMachine) embeds a Handle, which keeps the Objective-C pointer in an unexported field. When one generated package needs to call an Objective-C method on a wrapper owned by another generated package, it reads that pointer with IDOf.

The accessor that exposes the pointer is unexported, and this package lives in an "internal" directory, which Go only allows nearby packages (the generated layer itself) to import. Together that means application code cannot reach the raw pointer through here, so the public API stays free of Objective-C runtime types while the generated packages can still cooperate internally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IDOf

func IDOf(o Object) objc.ID

IDOf returns the Objective-C pointer held by o, or 0 if o is nil.

func Track

func Track[T Object](o T)

Track arranges for the Objective-C object behind o to be released when o is garbage collected. A newly created Objective-C object comes back with a reference that the Go side owns; Track installs the matching release so the object's memory is reclaimed once nothing in Go refers to it. o must be a pointer (every generated wrapper is). The finalizer reads the pointer through the same atomic as Release, so a wrapper released explicitly is not released a second time when it is collected.

Types

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

Handle holds the Objective-C object pointer for one wrapper. Wrapper types embed a Handle; the pointer field is unexported so it cannot be read from outside this package.

The pointer is read and cleared atomically (see idAddr), which is what makes Release idempotent and safe to call from multiple goroutines: exactly one caller observes the non-zero pointer and sends the release.

func Wrap

func Wrap(id objc.ID) Handle

Wrap returns a Handle holding the given Objective-C object pointer. Generated constructors call it when building a wrapper; the assignment copy is safe because it happens before the wrapper is shared.

func (*Handle) Release

func (h *Handle) Release()

Release relinquishes the Go side's reference to the Objective-C object, releasing it immediately instead of waiting for the garbage collector to run the wrapper's finalizer. It is idempotent and safe to call concurrently; after Release the wrapper's finalizer finds a zero pointer and does nothing.

After Release, calls through the wrapper send their message to nil, which Objective-C defines as a no-op returning zero — so a released wrapper's methods return zero values rather than crashing. Use Release for objects that hold scarce resources (files, sockets, virtual machines) where waiting for the collector is not acceptable:

config := virtualization.NewVirtualMachineConfiguration()
defer config.Release()

type Object

type Object interface {
	// contains filtered or unexported methods
}

Object is satisfied by every generated wrapper, because every wrapper embeds a Handle. The generated packages use Object to accept "any Objective-C object" in internal helpers; only this package can turn one back into a pointer, via IDOf.

Jump to

Keyboard shortcuts

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