# Controllers don't seemed to be released at the end of a request

**URL:** <https://www.ruby-forum.com/t/controllers-dont-seemed-to-be-released-at-the-end-of-a-request/126953>\
**Category:** Rails\
**Created:** [January 23, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/controllers-dont-seemed-to-be-released-at-the-end-of-a-request/126953 "2008-01-23T19:09:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![baldmountain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@baldmountain](https://www.ruby-forum.com/u/baldmountain)\
**Post date:** [January 23, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/controllers-dont-seemed-to-be-released-at-the-end-of-a-request/126953/1 "2008-01-23T19:09:09Z")

</div>

Controllers seem to be leaked in 1.2.6 but not in 2.0.2. I created an  
empty rails app with nothing but the following controller:

class HomeController \< ApplicationController  
def index  
@contents = []  
1.upto(2000) {  
@contents \<\< “big long string.”  
}  
end  
end

where "big long string is about 1K long. This creates a controller  
with a member variable with a good 2 megs worth of stuff hanging off  
it. (@contents) If I run this controller in 1.2.6, and then exercise  
the app, it leaks like a sieve, but in 2.0.2 it doesn’t. I was  
wondering what is hanging onto controllers at the end of a request? I  
can work around the issue by setting @contents to nil or an empty  
array at the end of the template but that seems like a hack and the  
app is still leaking controllers.

Does anyone know what changed in 2.0.2 so that controllers can be  
collected?

---

<div class="post-metadata">

**Author:** ![baldmountain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@baldmountain](https://www.ruby-forum.com/u/baldmountain)\
**Post date:** [January 23, 2008, 10:00pm UTC](https://www.ruby-forum.com/t/controllers-dont-seemed-to-be-released-at-the-end-of-a-request/126953/2 "2008-01-23T22:00:30Z")

</div>

Sigh. I think Im wrong about this. I added a finalizer using  
ObjectSpace.define\_finalizer to the controller where it is created in  
base.rb. The act of defining the finalizer seems to keep the item from  
being collected. Sigh. Taking out the define\_finalizer seems to fix  
the issue.

On the other hand something still holding onto my controllers in my  
full app.

---

<div class="post-metadata">

**Author:** ![baldmountain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@baldmountain](https://www.ruby-forum.com/u/baldmountain)\
**Post date:** [January 23, 2008, 11:51pm UTC](https://www.ruby-forum.com/t/controllers-dont-seemed-to-be-released-at-the-end-of-a-request/126953/3 "2008-01-23T23:51:00Z")

</div>

On Jan 23, 2008 12:59 PM, baldmountain [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On the other hand something still holding onto my controllers in my  
> full app.

We were investigating something similar recently at the day job, and  
tracked things back to routing. I’ll try and dig up our findings.

~ j.

---

<div class="post-metadata">

**Author:** ![baldmountain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a87d85/32.png) [@baldmountain](https://www.ruby-forum.com/u/baldmountain)\
**Post date:** [January 24, 2008, 1:25pm UTC](https://www.ruby-forum.com/t/controllers-dont-seemed-to-be-released-at-the-end-of-a-request/126953/4 "2008-01-24T13:25:46Z")

</div>

That would be great. I’ll also start looking into routing myself.  
Thanks for the pointer.
