cObj = $cObj; $this->managed = $managed; } /** * Mark backing C object as freed */ public function freed() { $this->freed = true; } public function isFreed(): bool { return $this->freed; } public function ensureNotFreed() { if ($this->isFreed()) { throw new \RuntimeException("object " . get_class($this) . " already freed, can't be used"); } } /** * Free backing C object, object is useless after this operation */ final public function free(): bool { if ($this->freed || (!$this->managed || $this->refCount > 0)) { return false; } $this->freeObject(); $this->freed(); return true; } protected function freeObject() { FFI::free($this->cObj); } public function __destruct() { $this->free(); } public function unmanaged() { $this->managed = false; } public function pushRefCount() { $this->refCount++; } public function decreaseRefCount() { $this->refCount--; } public function getRefCount() { return $this->refCount; } public function managed() { $this->managed = true; } public function getCData(): CData { return $this->cObj; } }