From: Shan-leung Maverick WOO Date: 2001-07-05T12:43:59+09:00 Subject: [ruby-talk:17271] Re: extension and GC Yukihiro Matsumoto wrote: > (1) override instance method "initialize", instead of overriding > class method "new". Wow! That works so well that I don't even need to call super in my initialize (as the "new" of Hash will call "initialize"). Great. > (2) depends on when do you want to deallocate your memory, but > global finalizer rb_set_end_proc() may help. See ext/curses.c I think this doesn't quite work in my case because the user can potentially create tons of such objects. To cast the question better, let me put up a hypothetical scenario: - I am going to re-implement the dbm package by inheriting from Hash (instead of the current way which is to mimic a hash). - The current way in dbm to release any allocated memory is in fdbm_close. (In reality, there is no memory allocated, but let's assume we did have some.) - I don't want my user to have to call "close" this time. I want the database to be closed when the object is GC'ed. And so, when the object is GC'ed, I better free the memory I allocated in my C code. Otherwise, all these memory are wasted while my program is running. How can I achieve this effect without waiting all the way through Ruby exit, which is what rb_set_end_proc buys me? Thanks!!! -- All the best, Maverick Woo