# Destroy object from memory.. Object.const\_destroy?

**URL:** <https://rubytalk.org/t/destroy-object-from-memory-object-const-destroy/38849>\
**Category:** ruby-talk\
**Created:** [4 July 2007 18:56 UTC](https://rubytalk.org/t/destroy-object-from-memory-object-const-destroy/38849 "2007-07-04T18:56:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@Aaron\_Smith](https://rubytalk.org/u/Aaron_Smith)\
**Post date:** [4 July 2007 18:56 UTC](https://rubytalk.org/t/destroy-object-from-memory-object-const-destroy/38849/1 "2007-07-04T18:56:01Z")

</div>

Hey all,

If I'm instantiating a instance of a class at using Object.const\_get.  
How can I destroy it so that next time it reloads and code changes will  
take effect?

Thanks.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Yukihiro\_Matsumoto2](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yukihiro\_Matsumoto2](https://rubytalk.org/u/Yukihiro_Matsumoto2)\
**Post date:** [5 July 2007 14:32 UTC](https://rubytalk.org/t/destroy-object-from-memory-object-const-destroy/38849/2 "2007-07-05T14:32:28Z")

</div>

Hi,

> If I'm instantiating a instance of a class at using Object.const\_get.  
> How can I destroy it so that next time it reloads and code changes will  
> take effect?

I am not sure what you mean here. You don't instantiate anything  
using const\_get. You just get the reference to the existing object.  
If you want to redefine class objects (without warning), you remove  
the constant using remove\_const(), and reload the program using  
load(). But I'd recommend restarting the program, unless reloading is  
absolutely necessary.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.

> **···**
>
> In message "Re: Destroy object from memory.. Object.const\_destroy?" on Thu, 5 Jul 2007 03:56:01 +0900, Aaron Smith \<beingthexemplary@gmail.com\> writes:

---

<div class="post-metadata">

**Author:** ![Aaron\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@Aaron\_Smith](https://rubytalk.org/u/Aaron_Smith)\
**Post date:** [5 July 2007 14:40 UTC](https://rubytalk.org/t/destroy-object-from-memory-object-const-destroy/38849/3 "2007-07-05T14:40:25Z")

</div>

Yukihiro Matsumoto wrote:

> Hi,
> 
> \>If I'm instantiating a instance of a class at using Object.const\_get.  
> \>How can I destroy it so that next time it reloads and code changes will  
> \>take effect?
> 
> I am not sure what you mean here. You don't instantiate anything  
> using const\_get. You just get the reference to the existing object.  
> If you want to redefine class objects (without warning), you remove  
> the constant using remove\_const(), and reload the program using  
> load(). But I'd recommend restarting the program, unless reloading is  
> absolutely necessary.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.

Thanks,

That's pretty much what I was looking for. The problem I'm having is  
with a plugin in Rails. Once it runs, if code is executed, then changed  
at all, I have to restart Rails. Default rails controllers update just  
fine. They're probably using the remove\_const(). But with my plugin I  
want to have the same functionality...

Are there any major risks doing this? Wouldn't seem like it.  
Thanks

> **···**
>
> > In message "Re: Destroy object from memory.. Object.const\_destroy?" \> on Thu, 5 Jul 2007 03:56:01 +0900, Aaron Smith \> \<beingthexemplary@gmail.com\> writes:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [5 July 2007 14:51 UTC](https://rubytalk.org/t/destroy-object-from-memory-object-const-destroy/38849/4 "2007-07-05T14:51:14Z")

</div>

Are you talking about the way Rails reloads classes in development mode? You can enable this in your own classes using:

&nbsp;&nbsp;&nbsp;class MyClass  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include Reloadable  
&nbsp;&nbsp;&nbsp;end

James Edward Gray II

> **···**
>
> On Jul 5, 2007, at 9:40 AM, Aaron Smith wrote:
> 
> > Yukihiro Matsumoto wrote:
> > 
> > > Hi,
> > > 
> > > In message "Re: Destroy object from memory.. Object.const\_destroy?" \>\> on Thu, 5 Jul 2007 03:56:01 +0900, Aaron Smith \>\> \<beingthexemplary@gmail.com\> writes:
> > > 
> > > \>If I'm instantiating a instance of a class at using Object.const\_get.  
> > > \>How can I destroy it so that next time it reloads and code changes will  
> > > \>take effect?
> > > 
> > > I am not sure what you mean here. You don't instantiate anything  
> > > using const\_get. You just get the reference to the existing object.  
> > > If you want to redefine class objects (without warning), you remove  
> > > the constant using remove\_const(), and reload the program using  
> > > load(). But I'd recommend restarting the program, unless reloading is  
> > > absolutely necessary.
> > > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matz.
> > 
> > Thanks,
> > 
> > That's pretty much what I was looking for. The problem I'm having is  
> > with a plugin in Rails. Once it runs, if code is executed, then changed  
> > at all, I have to restart Rails. Default rails controllers update just  
> > fine. They're probably using the remove\_const(). But with my plugin I  
> > want to have the same functionality...

---

<div class="post-metadata">

**Author:** ![Aaron\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@Aaron\_Smith](https://rubytalk.org/u/Aaron_Smith)\
**Post date:** [5 July 2007 15:03 UTC](https://rubytalk.org/t/destroy-object-from-memory-object-const-destroy/38849/5 "2007-07-05T15:03:08Z")

</div>

> > That's pretty much what I was looking for. The problem I'm having is  
> > with a plugin in Rails. Once it runs, if code is executed, then  
> > changed  
> > at all, I have to restart Rails. Default rails controllers update just  
> > fine. They're probably using the remove\_const(). But with my plugin I  
> > want to have the same functionality...
> 
> Are you talking about the way Rails reloads classes in development  
> mode? You can enable this in your own classes using:
> 
> &nbsp;&nbsp;&nbsp;class MyClass  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include Reloadable  
> &nbsp;&nbsp;&nbsp;end
> 
> James Edward Gray II

That's another good solution. Thanks.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
