php

SyncSharedMemory - how to relsease the object and memory


Can the SyncSharedMemory be used in production environments?

Why can't we find any definition of destroy or release methods?

The same as SyncReaderWriter, Unable to find any definition for releasing resources.

class SyncSharedMemory {
    public __construct(string $name, int $size)
    public first(): bool
    public read(int $start = 0, int $length = ?)
    public size(): int
    public write(string $string = ?, int $start = 0)
}

Solution

  • You can remove any references by setting the instance to null.

    $instance = new SyncSharedMemory('test', 100);
    $instance = null;
    

    Then, when the garbage collector will run, it will release it.

    You can force to collect earlier by calling, but you should avoid that.

    gc_collect_cycles();