Force_recycle

Hi,

At Wed, 10 Aug 2005 23:48:00 +0900,
Kroeger Simon (ext) wrote in [ruby-talk:151506]:
> Ok, perhaps I (wanted to) misinterpret Nobu's 'no'. I thought this
> refers to the accessibility from within ruby.

Sorry, I was too terse.

The reason why it is not accessible from ruby is that it's too
dangerous; it can cause crash easily if it were possible.

Consider:

  x = Foo.new
  GC.force_recycle(x)
  x.inspect

Accessing recycled object would raise "terminated object"
exception if you're lucky.

--
Nobu Nakada

:slight_smile:

I'm not lucky,

but that's ok. I have a rather large project here and it is eating
memory. I thought it would be nice to delete the objects we think are
obsolet and see where it goes down.
I wrote an extension do be able to access rb_gc_force_recycle.

Here is my test:

···

-------------------------------------------------
require 'force_recycle'

class A
    def a
        return 'foo'
    end
end

$stdin.sync = true

a = A.new
b = A.new

puts a.a

ObjectSpace.each_object(A){|o| p o}

force_recycle(a)
GC.start

puts 'After GC'
ObjectSpace.each_object(A){|o| p o}

puts a.a # BOOOOM
-------------------------------------------------

and the output:
-------------------------------------------------
foo
#<A:0x2a67760>
#<A:0x2a677d8>
After GC
#<A:0x2a67760>

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.
-------------------------------------------------

I would have been realy happy if I got the exception (and
the traceback).

So I have to think about another way...

Simon

fork - and do work in multiple processes. all memory is freed when the
process exits. ipc is trivial in ruby using local drb objects. i use this
alot for that

   http://raa.ruby-lang.org/project/slave/

it's designed so the child cannot, under any circumstances, outlive the parent
- so no zombies. the children (slaves) can be killed if needed though.

another option is mmap. guy's mmap interface can save on memory big time if
you're eating it up reading files...

cheers.

-a

···

On Thu, 11 Aug 2005, Kroeger Simon (ext) wrote:

I would have been realy happy if I got the exception (and
the traceback).

So I have to think about another way...

--

email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death Like a lamp standing in a strong breeze. --Nagarjuna

===============================================================================

Hi,

At Thu, 11 Aug 2005 00:16:10 +0900,
Kroeger Simon (ext) wrote in [ruby-talk:151514]:

but that's ok. I have a rather large project here and it is eating
memory. I thought it would be nice to delete the objects we think are
obsolet and see where it goes down.

The wrong thing is that you misuse GC to maintain expensive
(or external) resources. Use a releasing method and blocks to
ensure they get called.

<Ensuring post process>
http://www.rubyist.net/~matz/slides/oscon2005/mgp00047.html
http://www.rubyist.net/~matz/slides/oscon2005/mgp00048.html
http://www.rubyist.net/~matz/slides/oscon2005/mgp00049.html

···

--
Nobu Nakada