Comments found in ObjectSpace

Amarison wrote:

I ran the following code:

all =

ObjectSpace.each_object do |obj|
  all << obj
end

File.open('objectspace.txt','w') do |f|
  f.puts all
end

and I was surprised to find comments in objectspace.txt. I was under
the impression that Ruby skips comments when parsing code.

Very strange behaviour... Anyone cares to explain? Thanks

I don't see the comments when I run on FreeBSD, but I do see them when I run
on Windows. I'm guessing this is source code that has previously been
parsed, but not yet garbage collected. If I add ObjectSpace.garbage_collect
at the beginning of the program, the source code doesn't show up any longer.

Yeah, I am on Windows.

on Windows. I'm guessing this is source code that has previously been
parsed, but not yet garbage collected. If I add

ObjectSpace.garbage_collect

Great. That explains it. Thanks.

"Bob Showalter" <Bob_Showalter@taylorwhite.com> wrote in message
news:2E4528861499D41199D200A0C9B15BC005EE80AB@fristx.taylorwhite.com...

Amarison wrote:
> I ran the following code:
>
> all =
>
> ObjectSpace.each_object do |obj|
> all << obj
> end
>
> File.open('objectspace.txt','w') do |f|
> f.puts all
> end
>
>
> and I was surprised to find comments in objectspace.txt. I was under
> the impression that Ruby skips comments when parsing code.
>
> Very strange behaviour... Anyone cares to explain? Thanks

I don't see the comments when I run on FreeBSD, but I do see them when I

run

on Windows. I'm guessing this is source code that has previously been
parsed, but not yet garbage collected. If I add

ObjectSpace.garbage_collect

at the beginning of the program, the source code doesn't show up any

longer.

···

This got me thinking. Would it be a 'good practice' to run
ObjectSpace.garbage_collect at the beginning of any Ruby program? Any
benefits?

"Barson" <not.my.real.email@gmail.com> wrote in message
news:PtudnUa8n9MORdbenZ2dnUVZ_smdnZ2d@rogers.com...

···

Yeah, I am on Windows.

> on Windows. I'm guessing this is source code that has previously been
> parsed, but not yet garbage collected. If I add
ObjectSpace.garbage_collect

Great. That explains it. Thanks.

"Bob Showalter" <Bob_Showalter@taylorwhite.com> wrote in message
news:2E4528861499D41199D200A0C9B15BC005EE80AB@fristx.taylorwhite.com...
> Amarison wrote:
> > I ran the following code:
> >
> > all =
> >
> > ObjectSpace.each_object do |obj|
> > all << obj
> > end
> >
> > File.open('objectspace.txt','w') do |f|
> > f.puts all
> > end
> >
> >
> > and I was surprised to find comments in objectspace.txt. I was under
> > the impression that Ruby skips comments when parsing code.
> >
> > Very strange behaviour... Anyone cares to explain? Thanks
>
> I don't see the comments when I run on FreeBSD, but I do see them when I
run
> on Windows. I'm guessing this is source code that has previously been
> parsed, but not yet garbage collected. If I add
ObjectSpace.garbage_collect
> at the beginning of the program, the source code doesn't show up any
longer.
>
>
>

With GC runtime systems it's generally not recommended to do explicit GC as those algorithms in the GC usually do a good job. Although I believe the GC of Ruby is not yet as sophisticated as Java's I'm sure it's going to be at some point in time in the future.

Kind regards

    robert

···

Barson <not.my.real.email@gmail.com> wrote:

This got me thinking. Would it be a 'good practice' to run
ObjectSpace.garbage_collect at the beginning of any Ruby program? Any
benefits?