Forum: Ruby on Rails Class/Object lifecycle?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Lee (Guest)
on 2007-01-06 20:30
(Received via mailing list)
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.
Rick O. (Guest)
on 2007-01-06 20:31
(Received via mailing list)
On 1/4/07, Lee <removed_email_address@domain.invalid> 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/activesup...

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
This topic is locked and can not be replied to.