Skip to content

Instantly share code, notes, and snippets.

@sj-i
Created February 28, 2023 14:34
Show Gist options
  • Select an option

  • Save sj-i/23cdda81bf031688108a889b728e982b to your computer and use it in GitHub Desktop.

Select an option

Save sj-i/23cdda81bf031688108a889b728e982b to your computer and use it in GitHub Desktop.
Passing a callback to PHP FFI eats up memory because some internal data is not released until the end of the request
<?php
use FFI\CData;
$ffi = FFI::cdef('void qsort(void *base, size_t num, size_t size, int (*compare)(const void*, const void*));');
$arr = FFI::new('int[2]');
$arr[0] = 1;
$arr[1] = 2;
while (true) {
$ffi->qsort($arr, 2, FFI::sizeof($arr[0]), fn(CData $a, CData $b) => 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment