From: Eric Hodel Date: 2011-08-08T12:57:15+09:00 Subject: Re: Help in Pointer On Aug 6, 2011, at 10:08 PM, Tridib Bandopadhyay wrote: > Hans Mackowiak wrote in post #1014677: >>> Data_Wrap_Struct(klass, mark, free, ptr) >> >> >> if you use >> Data_Wrap_Struct(klass, 0, free, ptr) >> or >> Data_Wrap_Struct(klass, 0, -1, ptr) >> >> the pointer and the data will be freed >> if you use >> Data_Wrap_Struct(klass, 0, 0, ptr) >> the pointer will not be deleted or freed > > So will it make Memory Leak..!!!! No. If your object can be freed with free() then everything is fine. If your object needs to do special things then implement a custom free function. Ruby will collect the ruby objects inside your pointer when the GC knows it is OK provided you implement a mark function. You should have something like this: static void my_mark(my_pointer *ptr) { rb_gc_mark(ptr->ruby_object); } Data_Wrap_Struct(klass, my_mark, -1, ptr);