lib/ngt/index.rb in ngt-0.4.1 vs lib/ngt/index.rb in ngt-0.4.2

- old
+ new

@@ -7,14 +7,15 @@ def initialize(index, path) @index = index @path = path @error = FFI.ngt_create_error_object + FFI.add_finalizer(@error, :ngt_destroy_error_object) + @property = ffi(:ngt_create_property) + FFI.add_finalizer(@property, :ngt_destroy_property) ffi(:ngt_get_property, @index, @property) - - ObjectSpace.define_finalizer(self, self.class.finalize(@error, @index, @property)) end def dimensions @dimensions ||= ffi(:ngt_get_property_dimension, @property) end @@ -175,10 +176,12 @@ else ffi(:ngt_create_graph_and_tree_in_memory, property, error) end end + FFI.add_finalizer(index, :ngt_close_index) + super(index, path) ensure FFI.ngt_destroy_error_object(error) if error FFI.ngt_destroy_property(property) if property end @@ -193,18 +196,9 @@ end # private def self.ffi(*args) Utils.ffi(*args) - end - - def self.finalize(error, index, property) - # must use proc instead of stabby lambda - proc do - FFI.ngt_destroy_error_object(error) - FFI.ngt_close_index(index) - FFI.ngt_destroy_property(property) - end end private def narray?(data)