From: <jc...@gm...> - 2015-01-07 16:42:43
|
Hello everyone, I'm trying to use the ruby-gnome2 gobject-introspection package to help make a Ruby binding for my GObject-based image processing library. I have a general question about memory management: how is reference counting handled? For example, if I create a new object like this: a = Vips::Image.new and then get rid of the reference: a = nil GC.start I would expect the object to be unreffed. Is there some extra magic I need? Tiny test program here: https://github.com/jcupitt/ruby-vips8/blob/master/try/try2.rb John |
From: Kouhei S. <ko...@co...> - 2015-01-08 14:50:12
|
Hi, In <CAGNS0RsW3zKxgo=aX-...@ma...> "[ruby-gnome2-devel-en] ref and unref" on Wed, 7 Jan 2015 16:41:51 +0000, jc...@gm... wrote: > I'm trying to use the ruby-gnome2 gobject-introspection package to > help make a Ruby binding for my GObject-based image processing > library. > > I have a general question about memory management: how is reference > counting handled? For example, if I create a new object like this: > > a = Vips::Image.new > > and then get rid of the reference: > > a = nil > GC.start > > I would expect the object to be unreffed. Is there some extra magic I need? No. You don't need to anything. gobject-introspection gem (and glib2 gem) does everything. Try the following code: --- class X end a = X.new a = nil GC.start p(ObjectSpace.each_object(X) {}) --- It'll print "1". And also try the following code: --- class X end 1.times do X.new end GC.start p(ObjectSpace.each_object(X) {}) --- It'll print "0". I hope that they give you some hints. Thanks, -- kou |
From: <jc...@gm...> - 2015-01-08 16:40:32
|
Hi Kou, thank you very much for helping me. On 8 January 2015 at 14:50, Kouhei Sutou <ko...@co...> wrote: >> I have a general question about memory management: how is reference >> counting handled? For example, if I create a new object like this: >> >> a = Vips::Image.new >> >> and then get rid of the reference: >> >> a = nil >> GC.start >> >> I would expect the object to be unreffed. Is there some extra magic I need? > > No. You don't need to anything. > gobject-introspection gem (and glib2 gem) does everything. It doesn't seem to work for me. If I run: 10000.times do Vips::Image.new end GC.start I still have 10,000 GObjects, each with one ref. My code is here: https://github.com/jcupitt/ruby-vips8/blob/master/try/try2.rb#L98 Perhaps I am missing something in my loader class? Vips::image.new calls vips_image_new(), which just does g_object_new(): https://github.com/jcupitt/libvips/blob/master/libvips/iofuncs/image.c#L1681 John |
From: Kouhei S. <ko...@co...> - 2015-01-11 08:44:21
|
Hi, In <CAG...@ma...> "Re: [ruby-gnome2-devel-en] ref and unref" on Thu, 8 Jan 2015 16:39:45 +0000, jc...@gm... wrote: > It doesn't seem to work for me. If I run: > > 10000.times do > Vips::Image.new > end > GC.start > > I still have 10,000 GObjects, each with one ref. Really? > My code is here: > > https://github.com/jcupitt/ruby-vips8/blob/master/try/try2.rb#L98 I run the code with the following diff: -- diff --git a/try/try2.rb b/try/try2.rb index 53c4272..0b214fa 100755 --- a/try/try2.rb +++ b/try/try2.rb @@ -97,6 +97,8 @@ end 10000.times do Vips::Image.new end +p(ObjectSpace.each_object(Vips::Image) {}) GC.start +p(ObjectSpace.each_object(Vips::Image) {}) -- I got the following: -- Vips::const_missing: Image Vips::init: [] Vips::Loader.initialize: Vips, [] Vips::Loader.pre_load: #<GObjectIntrospection::Repository:0x0000000286eaa0>, Vips Vips::Loader.call_init_function: #<GObjectIntrospection::Repository:0x0000000286eaa0>, Vips Vips::Loader.post_load: 41 0 -- Did you use the latest gobject-introspection gem? I used gobject-introspection 2.2.4 gem: -- % gem list gobject-introspection *** LOCAL GEMS *** gobject-introspection (2.2.4) -- Thanks, -- kou |
From: <jc...@gm...> - 2015-01-30 14:07:55
|
Ooop, excuse me, I think I found my problem. gobject-introspection seems to be reffing the object it gets back from vips_image_new(), even though constructors should not do this (I think). How can I stop gobject-introspection from making this extra reference? If I run this code: x = Vips::Image.new x.print_dump at the end of the C vips_image_new() function, the object has a reference count of 1. But when x.print_dump runs, I see a count of 2. When I then run: x = nil GC.start the count drops to 1, but never to zero, so the object is not freed. I tried adding a (transfer full) annotation to vips_image_new(), but it made no difference, gobject-introspection still made an extra g_object_ref() during new. John |
From: <jc...@gm...> - 2015-01-31 13:40:53
|
On 31 January 2015 at 12:47, Kouhei Sutou <ko...@co...> wrote: > I've fixed it at master. Could you try master again? It works!! I now see: -------------------- $ ./example1.rb starting up: Vips::method_missing: leak_set, [true], Vips::init: [] Vips::Loader.initialize: Vips, [] Vips::Loader.pre_load: #<GObjectIntrospection::Repository:0x00000001d3fe18>, Vips Vips::Loader.call_init_function: #<GObjectIntrospection::Repository:0x00000001d3fe18>, Vips Vips::Loader.post_load: creating object: 1x1 uchar, 1 band, multiband, partial VipsImage (0x20a7010) 1 objects alive: 0) VipsImage (0x20a7010), count=1 VipsImage (image), image class 1x1 uchar, 1 band, multiband freeing object: shutting down: memory: high-water mark 0 bytes ------------------- Wonderful, thank you very much kou. John |
From: Kouhei S. <ko...@co...> - 2015-01-31 13:49:13
|
Hi, In <CAG...@ma...> "Re: [ruby-gnome2-devel-en] ref and unref" on Sat, 31 Jan 2015 13:40:05 +0000, jc...@gm... wrote: >> I've fixed it at master. Could you try master again? > > It works!! I now see: Thanks for confirming it! -- kou |
From: Kouhei S. <ko...@co...> - 2015-01-31 12:47:40
|
Hi, Thanks for the information! I've fixed it at master. Could you try master again? Thanks, -- kou In <CAG...@ma...> "Re: [ruby-gnome2-devel-en] ref and unref" on Fri, 30 Jan 2015 14:07:06 +0000, jc...@gm... wrote: > Ooop, excuse me, I think I found my problem. > > gobject-introspection seems to be reffing the object it gets back from > vips_image_new(), even though constructors should not do this (I > think). How can I stop gobject-introspection from making this extra > reference? > > If I run this code: > > x = Vips::Image.new > x.print_dump > > at the end of the C vips_image_new() function, the object has a > reference count of 1. But when x.print_dump runs, I see a count of 2. > When I then run: > > x = nil > GC.start > > the count drops to 1, but never to zero, so the object is not freed. > > I tried adding a (transfer full) annotation to vips_image_new(), but > it made no difference, gobject-introspection still made an extra > g_object_ref() during new. > > John > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en |
From: <jc...@gm...> - 2015-01-30 13:16:53
|
Hello again, sorry for the long delay, I was called off onto another project. On 11 January 2015 at 08:44, Kouhei Sutou <ko...@co...> wrote: >> It doesn't seem to work for me. If I run: >> >> 10000.times do >> Vips::Image.new >> end >> GC.start >> >> I still have 10,000 GObjects, each with one ref. > > I got the following: > > -- > Vips::const_missing: Image > Vips::init: [] > Vips::Loader.initialize: Vips, [] > Vips::Loader.pre_load: #<GObjectIntrospection::Repository:0x0000000286eaa0>, Vips > Vips::Loader.call_init_function: #<GObjectIntrospection::Repository:0x0000000286eaa0>, Vips > Vips::Loader.post_load: > 41 > 0 Thank you for trying this. That's counting instances of the Ruby classes, which I agree are being freed. But the underlying GObjects are not being unreffed. If you put a breakpoint on vips_object_finalize(), for example, it is never called. How can I get gobject-introspection to call g_object_unref() whan an object is removed by GC? > Did you use the latest gobject-introspection gem? I used > gobject-introspection 2.2.4 gem: Yes, I'm using 2.2.4. John |