最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

poppler - Do I need to manually free memory when using Haskell GI library? - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论