-
Assume I am writing an API where a heap-allocated byte buffer is returned from Rust to Dart side. The byte buffer will be processed by some Dart code, and then it should be deallocated. I was wondering if there's any approach to automatically do the deallocation job by, for example, calling a Rust deallocator function when the Dart object is about to be GCed, or I must manually call the deallocator by myself? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
If you say if you say any arbitrary data, they are copied (instead of zero-copy) to Flutter, and it is still Flutter's job to deallocate. |
Beta Was this translation helpful? Give feedback.
-
@fzyzcjy Thanks for your reply! btw, is it possible to implement zero-copied arbitary struct that can also be auto-deallocated? Currently only typed arrays support this feature. I've spotted there's |
Beta Was this translation helpful? Give feedback.
If you say
ZeroCopyBuffer<Vec<u8>>
, then it is auto deallocated when Dart decides to dispose it. Details can be found inallo-isolate
, which is a wrapper around Dart's C api.if you say any arbitrary data, they are copied (instead of zero-copy) to Flutter, and it is still Flutter's job to deallocate.