haskellpopplergobject-introspection

Do I need to manually free memory when using Haskell GI library?


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?


Solution

  • 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.