Clearing the RAM

Hey,
I was wondering, is there a way to clear the RAM Ruby uses in some
code? For instance, if I read in an entire file into the memory, can
I clear the RAM that was used?

thanks,
~ Ari
English is like a pseudo-random number generator - there are a
bajillion rules to it, but nobody cares.

Ari B. wrote:

Hey,
I was wondering, is there a way to clear the RAM Ruby uses in some
code? For instance, if I read in an entire file into the memory, can I
clear the RAM that was used?

I guess that would probably be quite difficult because the language
doesn’t guarantee anything regarding where the memory is allocated, when
it is freed, overwritten or reallocated. You may want to implement this
in something closer to the metal like C where you get this kind of
control.

If you really must use Ruby I suppose that if you pay attention to the
objects you use to store the data from the file and find out how they
use memory (by looking at the actual Ruby C source code mainly) then you
could probably read the file, track all objects passed information you
want to protect and define methods that you know (from actual C source
reading) will overwrite any important information left around. You’ll
have to make sure your code runs on the exact smae version of the
interpreter and libs you used when examining the sources. Messy…

A simpler way (but maybe not workable for you) would be to fork to
handle the file processing and run the whole code on an OS which
scrambles memory of terminated processes (I’m not sure, but hardened
versions of Linux might very well implement this).

Lionel.

Ari B. wrote:

Hey,
I was wondering, is there a way to clear the RAM Ruby uses in some
code? For instance, if I read in an entire file into the memory, can I
clear the RAM that was used?

I think the only way you could do that (or at least the only practical
way) would be to define a special-purpose class in a C extension and use
instances of the class to allocate the memory and control whatever goes
into it. When GC says you can free the memory then you can set it to
all-bits-0 or whatever other action constitutes “clearing.”

I was wondering, is there a way to clear the RAM Ruby uses in some
code? For instance, if I read in an entire file into the memory, can
I clear the RAM that was used?

Good way to guarantee 100% is to reboot :slight_smile:

That’s not always desirable though…

-Doug

On 6/25/07, Ari B. [email protected] wrote:

Hey,
I was wondering, is there a way to clear the RAM Ruby uses in some
code? For instance, if I read in an entire file into the memory, can
I clear the RAM that was used?

The memory is freed for your application’s use when all references to
it are broken. It’s not given back to the operating system, though.

The classic way to do this is to restart your program with
Kernel#exec() (perhaps in response to a SIGHUP)

I mean freeing it.

On Jul 1, 2007, at 12:43 PM, SonOfLilit wrote:

thanks,
~ Ari
English is like a pseudo-random number generator - there are a
bajillion rules to it, but nobody cares.

~ Ari
English is like a pseudo-random number generator - there are a
bajillion rules to it, but nobody cares.

Then just fire up the garbage collector explicitly.

Ruby already does it’s own garbage collection, but you can explicitly
tell it to by putting

GC.start

in your code after a heavy memory action. Also good to nil out any
variables that you know you have finished with to give the GC a good
heads up on which memory blocks it can safely ditch.

See module GC - RDoc Documentation for the API

Regards

Mikel

Do you mean zero it to disallow peeking, or do you mean freeing it?

Aur