Class/Object lifecycle?

I understand that all application classe files are reloaded before
processing each HTTP request when in development mode (by default,
using Ruby “load”). I assume therefore that the corresponding class
objects (controller, model) are also created at the same time, along
with dynamically created methods such as those required for
associations such as has_many. Correct so far?

What happens to these class objects and other objects created during
request processing - i.e. controller and model objects such as created
by c=Customer.new - at the completion of request processing lifecycle
(post-render)? Do they get swept up by garbage collection? Is the
behaviour the same in production mode? Does anything persist between
requests, apart from session (and flash) objects?

Thanks.

On 1/4/07, Lee [email protected] wrote:

I understand that all application classe files are reloaded before
processing each HTTP request when in development mode (by default,
using Ruby “load”). I assume therefore that the corresponding class
objects (controller, model) are also created at the same time, along
with dynamically created methods such as those required for
associations such as has_many. Correct so far?

That’s correct. When Rails initializes, it loads only the framework
and plugins. After that, controllers/models/etc are loaded as they’re
used in your app.

What happens to these class objects and other objects created during
request processing - i.e. controller and model objects such as created
by c=Customer.new - at the completion of request processing lifecycle
(post-render)? Do they get swept up by garbage collection? Is the
behaviour the same in production mode? Does anything persist between
requests, apart from session (and flash) objects?

Const.remove is called on them I believe. See more in the
Dependencies module in ActiveSupport:
http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/dependencies.rb

This doesn’t happen in production mode to keep it as fast as possible.
You won’t have classes being reloaded, running all the
metaprogramming magic (such as the various AR associations), or models
retrieving the table structure from the DB.


Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com