How to garbage collect an Idris/C Struct?

Viewed 95

I'd like Idris to garbage-collect my Idris Struct. The docs for Struct FFI say

The field types of a Struct can be any of the following:

  • ...
  • Ptr a or AnyPtr (void* in C)
  • Another Struct, which is a pointer to a struct in C

and offer the following functions from the Prelude to enable garbage collection on pointers

onCollect : Ptr t -> (Ptr t -> IO ()) -> IO (GCPtr t)
onCollectAny : AnyPtr -> (AnyPtr -> IO ()) -> IO GCAnyPtr

Having read the quote above, I'd think it's possible to use these functions for automatic memory management of my Idris Struct (that perhaps Struct is a wrapper/alias for Ptr), but looking at the definitions of Struct and Ptr

data Struct : String -> List (String, Type) -> Type where

data Ptr : Type -> Type where [external]

that appears not to be the case. Is there some way to automatically memory manage structs in Idris?

0 Answers
Related