admin管理员组

文章数量:1356585

In the Haskell GI libraries, there are many functions for freeing memory. For example destFree in GI.Poppler.Structs.Dest. Do they really have to be used? Haskell has its own garbage collector, so I would think, I should not be worried about freeing memory. Is it possible, by chance, that those functions are just auto-generated by the GObject introspection mechanism, and should not actually be used?

In the Haskell GI libraries, there are many functions for freeing memory. For example destFree in GI.Poppler.Structs.Dest. Do they really have to be used? Haskell has its own garbage collector, so I would think, I should not be worried about freeing memory. Is it possible, by chance, that those functions are just auto-generated by the GObject introspection mechanism, and should not actually be used?

Share Improve this question asked Mar 27 at 21:49 amkhlvamkhlv 3493 silver badges14 bronze badges 1
  • I have no clue about the library in question so I'm not answering, but in general if Haskells GC didn't allocate the memory it has no clue when to deallocate it. The GC only cares for and frees memory that it manages, memory allocated through FFI is not managed by the GC. It might very well be that the library wraps the objects in a proper way, but just because Haskell has a GC doesn't mean you never need to free anything. – cafce25 Commented Mar 27 at 21:54
Add a comment  | 

1 Answer 1

Reset to default 2

No. The GI infrastructure connects GHC's garbage collection with glib's reference counting on your behalf, so everything is handled automatically. You can inspect the details in the source. Check out newObject; almost all the libraries' exported opaque types actually wrap a ManagedPtr built with this.

本文标签: popplerDo I need to manually free memory when using Haskell GI libraryStack Overflow