I used this code
def x
puts "press return"
gets
end
class Foo; end
n = 100
x
f= Foo.new
n.times do |i|
f.instance_eval("@a_variable_#{i} = #{i}")
end
x
with n=100 ruby used 6.35M ( according to task manager), before and after
creating the variables
when n=100000000, it used 300M before I got bored of waiting
----- Original Message -----
From: Chris McMahon <[EMAIL PROTECTED]>
Date: Wednesday, March 28, 2007 10:15 am
Subject: Re: [Wtr-general] Can we use as many variable names without
worrying about memory wastage
> The number of variables is not going to be a problem. But watch out
> if you have for instance several arrays with 50,000 elements in each.
> Those can eat up some memory.
>
> Ruby has what's called a "garbage collector" that handles removing
> things that the script is done with.
> -Chris
>
> On 3/28/07, vijay <[EMAIL PROTECTED]> wrote:
> > Hello people,
> >
> > Can we use as many variable names as we want in a script without
> worrying about the memory wastage? Each variable is going to
> occupy some bytes in memory and those bytes would remain occupied
> as long as the script is running. If so, then in order to avoid
> memory wastage, to the maximum possible extent, we need to use as
> few variables as possible in the script. Is this right? Can I
> make Watir free the memory space occupied by a variable once I
> find that the variable is not needed anymore? Thinking on the
> lines of not wasting memory, I am using same variables again and
> again in the script. If I could find out a way, through you
> people, to free the memory space occupied by a variable, I would
> use several variables with appropriate names in the script.
> >
> > Thanks for your time,
> > Vijay.
> > _______________________________________________
> > Wtr-general mailing list
> > [email protected]
> > http://rubyforge.org/mailman/listinfo/wtr-general
> >
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
>
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general