Clearing the RAM

A

Ari Brown

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.
 
L

Lionel Bouton

Ari said:
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.
 
T

Tim Hunter

Ari said:
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."
 
B

Bob Showalter

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)
 
D

Doug Phillips

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

Good way to guarantee 100% is to reboot :)

That's not always desirable though...

-Doug
 
A

Ari Brown

I mean freeing it.

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


Aur

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

Mikel Lindsaar

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 http://www.ruby-doc.org/core/classes/GC.html for the API

Regards

Mikel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SCP Ruby 2
Polymorphic Code 31
[ANN] Free RAM 1.0 6
Alternate Regular Expressions? 25
AVL Tree 4
Rubinius on Mac PPC 3
Keylogging in Ruby 0
[ANN] fire 1.2.0 1

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top