﻿# rocDecode internal frames: releasing a surface requires completed consumers

Track the lifetime of rocDecode internal output surfaces through asynchronous preprocessing, distinguishing decoded readiness, consumer completion and decoder pool reuse.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-rocdecode-internal-frame-release-consumer-completion/
Language: en

## Identify which output mode owns the surface

A video pipeline obtains a decoded device pointer, launches preprocessing and immediately returns the surface to the decoder. It can work during a slow diagnostic run and fail when decoding advances faster. Begin by recording whether the output is an internal decoder surface or copied storage. The same device-pointer type does not establish the same ownership or reuse contract, and copied storage is not automatically an indefinitely retained application allocation.

## Separate decoded readiness from downstream completion

The [RocVideoDecoder utility reference](https://rocm.docs.amd.com/projects/rocDecode/en/latest/reference/rocDecode-util-decoder.html) distinguishes obtaining a frame and releasing it after processing. Obtaining usable decoded data answers whether the consumer may begin. It does not prove that a subsequently launched asynchronous kernel has finished reading. Record the consumer's completion condition with the frame identity instead of treating the host launch function's return as the end of processing.

## Preserve the memory-mode qualification

The [surface-memory guide](https://rocm.docs.amd.com/projects/rocDecode/en/latest/conceptual/rocDecode-memory-types.html) distinguishes internal, copied device, copied host and unmapped performance modes, with backend qualifications. ReleaseFrame applies to the documented internal-surface path. Do not apply its ownership assumptions indiscriminately to every decoder backend or interpret a decode-only unmapped benchmark as evidence that usable frame pixels were delivered to preprocessing. Keep the selected mode with every reproduction.

## Include decoder reconfiguration in the lifetime model

The [videodecode sample explanation](https://rocm.docs.amd.com/projects/rocDecode/en/latest/how-to/using-rocDecode-videodecode-sample.html) describes frame processing and buffer-pool changes during reconfiguration. Treat resolution changes as a boundary requiring explicit handling of remaining frames and outstanding consumers. A valid pointer from the previous pool cannot be assumed to remain meaningful after that pool is replaced. Preserve shape, surface format and frame identity alongside the lifetime decision.

## Test with a deliberately delayed consumer

Delay downstream work in a controlled test while continuing the decode loop, then verify that surfaces remain retained until their consumers complete. Test reconfiguration separately from steady-state reuse. The existing [cross-stream event guide](/journal/learn-cross-stream-event-dependency/) and [software reproducibility guide](/journal/software-stack-reproducibility/) provide context. Report decode completion, consumer completion and release as distinct events, so apparent zero-copy efficiency does not conceal a race caused by returning storage before its final reader is finished.
