Skip to content
Image docs0.3

Native Resource Lifecycle

Latest stable Based on Image release 0.3.0

libvips images are not ordinary garbage-collected values. Each VipsImage owns native state and implements AutoCloseable.

Loading, resizing, cropping, and other operations can each produce a new native image. Close the source and every result:

runtime.load(path).use { source ->
source.resize(640, 480).use { resized ->
resized.writeTo(output)
}
}

Do not return a VipsImage from a scope that already closed it. For application APIs, prefer returning encoded bytes, a file result, or a caller-owned closeable with explicit ownership.

Initialize either JVipsRuntime or FfmVipsRuntime during application startup. Shutdown is process-wide: no request, worker, or writer may still use libvips afterward. Framework destruction order must stop traffic and workers before shutting down the runtime.

The release config runs JNI and FFM tests with one test class per fork and one parallel fork. Preserve this isolation when adding CI jobs. Native failure can poison process state, and two backends can compete for the same global library.

Coroutine cancellation does not remove the need for use. Close in structured scopes and write final output atomically when partial files are unsafe. Bound input bytes and pixels before entering native decode.