From: matz@... (Yukihiro Matsumoto) Date: 2000-12-08T10:21:38+09:00 Subject: [ruby-talk:6923] Re: Ruby objects and memory management. Hi, In message "[ruby-talk:6887] Ruby objects and memory management." on 00/12/07, Ami Ganguli writes: | |Ok, I'm trying to figure out how to use ruby objects withing my application server. | |What I need is to create ruby objects outside the scope of the interpretor. |Certain objects will be long-lived (created at server config) and others will |be attached to a specific request and should be cleanly and reliably freed when |the request is finished. (1) Create arrays and assign them into C global variables. (2) Register the C global variables by using rb_global_variables. (3) Create objects by using rb_obj_alloc(), NEWOBJ(), Data_Make_Struct(), etc. (4) Let the objects referenced from the arrays above as long as they live. (5) Objects that no longer referenced from anywhere will be reclaimed by next GC. FYI, Ruby's GC is conservative, which means it does not consider your objects as garbage if they are referenced from C local variables. So you might not need to protect your request specific objects using above method. matz.