Forum: Ruby Clearing the RAM

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
425cab08658a06567879717de154552c?d=identicon&s=25 Ari Brown (Guest)
on 2007-06-26 00:18
(Received via mailing list)
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.
Bef7ff8a0537495a1876ffebdc9f8e51?d=identicon&s=25 Lionel Bouton (Guest)
on 2007-06-26 00:47
(Received via mailing list)
Ari Brown 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.
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Tim Hunter (Guest)
on 2007-06-26 01:01
(Received via mailing list)
Ari Brown 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."
813f535246722b7bf02aacc9ce818de8?d=identicon&s=25 Bob Showalter (Guest)
on 2007-06-26 19:40
(Received via mailing list)
On 6/25/07, Ari Brown <ari@aribrown.com> 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)
7b0e3a2c135e6f67edf3194ee501961d?d=identicon&s=25 Doug Phillips (Guest)
on 2007-07-01 05:48
(Received via mailing list)
> 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 :)

That's not always desirable though...

-Doug
7b4707f974af261f71943e1f2046c9ee?d=identicon&s=25 SonOfLilit (Guest)
on 2007-07-01 18:44
(Received via mailing list)
Do you mean zero it to disallow peeking, or do you mean freeing it?


Aur
425cab08658a06567879717de154552c?d=identicon&s=25 Ari Brown (Guest)
on 2007-07-02 16:45
(Received via mailing list)
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.
Fb1a6916e06f221b5b53a6665f9858eb?d=identicon&s=25 Mikel Lindsaar (Guest)
on 2007-07-03 01:11
(Received via mailing list)
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
This topic is locked and can not be replied to.