[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Clearing the RAM

Ari Brown

6/25/2007 10:18:00 PM

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.


7 Answers

Lionel Bouton

6/25/2007 10:47:00 PM

0

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.


Tim Hunter

6/25/2007 11:01:00 PM

0

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

--
RMagick OS X Installer [http://rubyforge.org/project...]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?for...]
RMagick Installation FAQ [http://rmagick.rubyforge.org/instal...]


Bob Showalter

6/26/2007 5:39:00 PM

0

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)

Doug Phillips

7/1/2007 3:47:00 AM

0

> 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

SonOfLilit

7/1/2007 4:44:00 PM

0

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


Aur

On 6/26/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?
>
> thanks,
> ~ Ari
> English is like a pseudo-random number generator - there are a
> bajillion rules to it, but nobody cares.
>
>
>

Ari Brown

7/2/2007 2:43:00 PM

0

I mean freeing it.

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

> Do you mean zero it to disallow peeking, or do you mean freeing it?
>
>
> Aur
>
> On 6/26/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?
>>
>> 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.


Mikel Lindsaar

7/2/2007 11:11:00 PM

0

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/class... for the API

Regards

Mikel

On 7/3/07, Ari Brown <ari@aribrown.com> wrote:
> I mean freeing it.
>
> On Jul 1, 2007, at 12:43 PM, SonOfLilit wrote:
>
> > Do you mean zero it to disallow peeking, or do you mean freeing it?
> >
> >
> > Aur
> >
> > On 6/26/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?
> >>
> >> 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.
>
>
>