Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Manual Memory Management and Automatic Garbage Collection

Reply
Thread Tools

Manual Memory Management and Automatic Garbage Collection

 
 
Tridib Bandopadhyay
Guest
Posts: n/a
 
      12-06-2010
Hello all

I am trying to do a research on Manual Memory Management and Automatic
Garbage Collection on Ruby.So i need to play with Garbage Collector code
of Ruby.I am using Ruby 1.8.6

I am also trying to figure out in Ruby when the Garbage Collector starts
working.But didn't got any clue.

I read somewhere in wiki about some systems that uses this design of
Memory Allocation.

Can any one help me in some of my queries:-

1. When the Garbage Collector starts working can I see it.(For e.g-It
will print like Garbage Collector starting.)Somebody referred me use
GC_NOTIFY but there is no such function in the gc.c file.

2. What are the main parts in Ruby Garbage Collector I need to know to
accomplish this research.

After I get my first step done I hope I will have many questions to
share with you all.

Regards...Eagerly waiting for a reply at the earliest

Tridib

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Jeremy Bopp
Guest
Posts: n/a
 
      12-06-2010
On 12/6/2010 8:41 AM, Tridib Bandopadhyay wrote:
> Hello all
>
> I am trying to do a research on Manual Memory Management and Automatic
> Garbage Collection on Ruby.So i need to play with Garbage Collector code
> of Ruby.I am using Ruby 1.8.6
>
> I am also trying to figure out in Ruby when the Garbage Collector starts
> working.But didn't got any clue.
>
> I read somewhere in wiki about some systems that uses this design of
> Memory Allocation.
>
> Can any one help me in some of my queries:-
>
> 1. When the Garbage Collector starts working can I see it.(For e.g-It
> will print like Garbage Collector starting.)Somebody referred me use
> GC_NOTIFY but there is no such function in the gc.c file.
>
> 2. What are the main parts in Ruby Garbage Collector I need to know to
> accomplish this research.
>
> After I get my first step done I hope I will have many questions to
> share with you all.
>
> Regards...Eagerly waiting for a reply at the earliest


Have you tried sprinkling some printf statements throughout gc.c
yourself yet? If the diagnostic instrumentation for gc.c is hard to
find or does not exist, adding your own can at least help you make some
progress.

To start, you could add a printf with the function name at the beginning
of each function in gc.c. Then run your build of ruby with your test
scripts to trigger garbage collection and see what gets printed. That
should give you a lead on where to add more printf calls to gc.c in
order to gather more detailed information.

-Jeremy

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      12-06-2010
On Mon, Dec 6, 2010 at 3:41 PM, Tridib Bandopadhyay <(E-Mail Removed)> wrote:

> I am trying to do a research on Manual Memory Management and Automatic
> Garbage Collection on Ruby.So i need to play with Garbage Collector code
> of Ruby.I am using Ruby 1.8.6
>
> I am also trying to figure out in Ruby when the Garbage Collector starts
> working.But didn't got any clue.


There were some threads here recently about GC. What specific
questions were left unanswered?

> I read somewhere in wiki about some systems that uses this design of
> Memory Allocation.
>
> Can any one help me in some of my queries:-
>
> 1. When the Garbage Collector starts working can I see it.(For e.g-It
> will print like Garbage Collector starting.)Somebody referred me use
> GC_NOTIFY but there is no such function in the gc.c file.


You know CPP (C preprocessor) defines and macros, do you? Please look
for "GC_NOTIFY".

> 2. What are the main parts in Ruby Garbage Collector I need to know to
> accomplish this research.


I haven't looked closely but I would start at the end of the file and
walk my way through reading from rb_gc_start(). You should hit all
main structures pretty soon.

> After I get my first step done I hope I will have many questions to
> share with you all.


OK, let's hear them.

> Regards...Eagerly waiting for a reply at the earliest


Please don't push it. It won't increase your chances of getting answers anyway.
http://www.catb.org/~esr/faqs/smart-...ns.html#urgent

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
Ammar Ali
Guest
Posts: n/a
 
      12-06-2010
On Mon, Dec 6, 2010 at 4:41 PM, Tridib Bandopadhyay <(E-Mail Removed)> wrote:
> Hello all
>
> 1. When the Garbage Collector starts working can I see it.(For e.g-It
> will print like Garbage Collector starting.)Somebody referred me use
> GC_NOTIFY but there is no such function in the gc.c file.


The GC_NOTIFY flag is not available in ruby 1.8, it's in 1.9 only. If
you have to use ruby 1.8, you can do it yourself by adding printf
calls at the begining an end of the rb_gc_start function in gc.c.
Under 1.9 the function where GC start is called gc_collect, or at
least that's where GC_NOTIFY is placed.

> 2. What are the main parts in Ruby Garbage Collector I need to know to
> accomplish this research.


I think this was suggested before, it will answer many of your questions.

http://timetobleed.com/garbage-colle...by-conference/

Regards,
Ammar

 
Reply With Quote
 
Tridib Bandopadhyay
Guest
Posts: n/a
 
      12-07-2010
Jeremy Bopp wrote in post #966541:

> Have you tried sprinkling some printf statements throughout gc.c
> yourself yet? If the diagnostic instrumentation for gc.c is hard to
> find or does not exist, adding your own can at least help you make some
> progress.
>
> To start, you could add a printf with the function name at the beginning
> of each function in gc.c. Then run your build of ruby with your test
> scripts to trigger garbage collection and see what gets printed. That
> should give you a lead on where to add more printf calls to gc.c in
> order to gather more detailed information.
>
> -Jeremy



Yes I have tried that long back.. for example in this code fragment--

VALUE
rb_newobj()
{
VALUE obj;
printf("newobj"); /*My own line*/
if (!freelist) garbage_collect();

obj = (VALUE)freelist;
freelist = freelist->as.free.next;
MEMZERO((void*)obj, RVALUE, 1);
#ifdef GC_DEBUG
RANY(obj)->file = ruby_sourcefile;
RANY(obj)->line = ruby_sourceline;
#endif
return obj;
}

But when I am making this change and trying to compile my ruby. It is
bombing out with a message Segmentation failure and it is printing my
print statement numerous times before bombing out.I also tried in my
other functions.

Also can you tell me when we compile the ruby with 'make' command how
does it changes the gc.c file in the executable file.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Tridib Bandopadhyay
Guest
Posts: n/a
 
      12-07-2010
Ammar Ali wrote in post #966575:

> The GC_NOTIFY flag is not available in ruby 1.8, it's in 1.9 only. If
> you have to use ruby 1.8, you can do it yourself by adding printf
> calls at the begining an end of the rb_gc_start function in gc.c.
> Under 1.9 the function where GC start is called gc_collect, or at
> least that's where GC_NOTIFY is placed.
>


> Regards,
> Ammar



I tried in there also.Here is the code.--


rb_gc_start()
{
rb_gc();
return Qnil;
printf("Hello!!")
}

It is compiling but is not showing the hello message when i am running
the code.Here is my ruby code--

print "Please enter number 1 : ";
val1 = gets;
print "Please enter number 2 : ";
val2 = gets;
print "Answer : " , (val1.to_i + val2.to_i), "\n";
ct = 1;
while(ct<100)
a=[];
na = 0;
while(na<1000)
a[na]=na;
na = na+1;
end;
print ct;
ct=ct+1;
end;

How to see that hello message and how to know when Garbage Collector is
doing its work.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Tridib Bandopadhyay
Guest
Posts: n/a
 
      12-07-2010
On One function void rb_gc() I added one printf statement of my own.

And when I type the command -

/ruby -e 'GC.start()'

Then it is showing me my print statement.But I want to see my print
statement when i am running one of my ruby codes.

Regards

Tridib

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Ammar Ali
Guest
Posts: n/a
 
      12-07-2010
On Tue, Dec 7, 2010 at 4:27 AM, Tridib Bandopadhyay <(E-Mail Removed)> wr=
ote:
>
> I tried in there also.Here is the code.--
>
>
> rb_gc_start()
> {
> =C2=A0 =C2=A0rb_gc();
> =C2=A0 =C2=A0return Qnil;
> =C2=A0 =C2=A0printf("Hello!!")
> }


It will never work. You're printing after return!

Regards,
Ammar

 
Reply With Quote
 
Tridib Bandopadhyay
Guest
Posts: n/a
 
      12-07-2010
Ammar Ali wrote in post #966734:
> On Tue, Dec 7, 2010 at 4:27 AM, Tridib Bandopadhyay <(E-Mail Removed)=
>
> wrote:
>>
>> I tried in there also.Here is the code.--
>>
>>
>> rb_gc_start()
>> {
>> =C2=A0 =C2=A0rb_gc();
>> =C2=A0 =C2=A0return Qnil;
>> =C2=A0 =C2=A0printf("Hello!!")
>> }

>
> It will never work. You're printing after return!
>
> Regards,
> Ammar


I shifted the printf statement above the return statement.Here is the =

output I am getting--

/ruby doug.rb
Please enter number 1 : 3
Please enter number 2 : 4
Answer : 7
12345678910111213141516171819202122232425262728293 03132333435363738394041=
42434445464748495051525354555657585960616263646566 67686970717273747576777=
8798081828384858687888990919293949596979899-bash-3.00$

Regards
Tridib

-- =

Posted via http://www.ruby-forum.com/.=

 
Reply With Quote
 
Walton Hoops
Guest
Posts: n/a
 
      12-07-2010
On 12/06/2010 08:48 PM, Tridib Bandopadhyay wrote:
> I shifted the printf statement above the return statement.Here is the
> output I am getting--
>
> ./ruby doug.rb
> Please enter number 1 : 3
> Please enter number 2 : 4
> Answer : 7
> 12345678910111213141516171819202122232425262728293 03132333435363738394041424344454647484950515253545 55657585960616263646566676869707172737475767778798 081828384858687888990919293949596979899-bash-3.00$

Most likely Garbage Collection is not being run for your (rather short)
script. Does your message print when you run GC.start()? If so your
message is working fine. Try writing something that creates a log of
garbage to be collected. I think something like:

i=1
while (true)
puts "message #{i}"
i+=1
end

should do the trick. Of course, that particular program will never exit.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slow manual 'garbage collection' in C++ ?? brey_maastricht@hotmail.com C++ 14 06-18-2008 05:14 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Summer School on Garbage Collection & Memory Management Richard Jones C Programming 0 04-29-2004 04:02 PM
Summer School on Garbage Collection & Memory Management Richard Jones C++ 0 04-29-2004 04:02 PM
Summer School on Garbage Collection & Memory Management Richard Jones Python 0 04-29-2004 04:02 PM



Advertisments