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 |