Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: FFI > Create managed binary data #481

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

tienvx
Copy link
Contributor

@tienvx tienvx commented Feb 17, 2024

FFI: Change from unmanaged data to managed data

For #371

Copy link
Collaborator

@Lewiscowles1986 Lewiscowles1986 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would appreciate any links you have on this, but I think it should help to prevent memory leaks if managed is the same type of [memory] management I'd think of. Interesting that it's not the default as past ffi, it's in PHP and should work as PHP would expect (managed)

@tienvx
Copy link
Contributor Author

tienvx commented Feb 17, 2024

Here is the link about $owned parameter of FFI::new():

https://www.php.net/manual/en/ffi.new.php#refsect1-ffi.new-parameters

owned: Whether to create owned (i.e. managed) or unmanaged data. Managed data lives together with the returned FFI\CData object, and is released when the last reference to that object is released by regular PHP reference counting or GC. Unmanaged data should be released by calling FFI::free(), when no longer needed.

What I did there is to keep the $cData object alive, by creating object of type BinaryData as a property of object of type Binary, which live long enough throughout the binary's consumer example.

@tienvx tienvx merged commit 0ab3a0a into pact-foundation:ffi Feb 17, 2024
30 checks passed
@tienvx tienvx deleted the create-managed-binary-data branch February 17, 2024 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants