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

In the Haskell GI libraries, there are many functions for freeing memory. For example destFree in GI.Po

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744066483a4552749.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信