c
// Increment reference count when assigning the stream
tile->pkthdrstream = jpc_streamlist_remove(dec->pkthdrstreams, 0);
if (tile->pkthdrstream) {
    jpc_stream_increment_ref(tile->pkthdrstream);
}

// Later in the code, when the stream is no longer needed
jpc_stream_decrement_ref(tile->pkthdrstream);
if (jpc_stream_ref_count(tile->pkthdrstream) == 0) {
    jpc_stream_free(tile->pkthdrstream);
}
