[#13775] Problems with racc rule definitions — Michael Neumann <neumann@...>

15 messages 2001/04/17
[#13795] Re: Problems with racc rule definitions — Minero Aoki <aamine@...> 2001/04/18

Hi,

[#13940] From Guido, with love... — Dave Thomas <Dave@...>

52 messages 2001/04/20

[#13953] regexp — James Ponder <james@...>

Hi, I'm new to ruby and am coming from a perl background - therefore I

19 messages 2001/04/21

[#14033] Distributed Ruby and heterogeneous networks — harryo@... (Harry Ohlsen)

I wrote my first small distributed application yesterday and it worked

15 messages 2001/04/22

[#14040] RCR: getClassFromString method — ptkwt@...1.aracnet.com (Phil Tomson)

It would be nice to have a function that returns a class type given a

20 messages 2001/04/22

[#14130] Re: Ruby mascot proposal — "Conrad Schneiker" <schneik@...>

Guy N. Hurst wrote:

21 messages 2001/04/24
[#14148] Re: Ruby mascot proposal — Stephen White <spwhite@...> 2001/04/24

On Tue, 24 Apr 2001, Conrad Schneiker wrote:

[#14188] Re: Ruby mascot proposal — matz@... (Yukihiro Matsumoto) 2001/04/25

Hi,

[#14193] Re: Ruby mascot proposal — "W. Kent Starr" <elderburn@...> 2001/04/25

On Tuesday 24 April 2001 23:02, Yukihiro Matsumoto wrote:

[#14138] Re: python on the smalltalk VM — Conrad Schneiker <schneik@...>

FYI: Thought this might be of interest to the JRuby and Ruby/GUI folks.

27 messages 2001/04/24
[#14153] Re: python on the smalltalk VM — Andrew Kuchling <akuchlin@...> 2001/04/24

Conrad Schneiker <schneik@austin.ibm.com> writes:

[#14154] array#flatten! question — Jim Freeze <jim@...> 2001/04/24

Hello.

[#14159] Can I insert into an array — Jim Freeze <jim@...> 2001/04/24

Ok, this may be a dumb question, but, is it possible to insert into an

[#14162] Re: Can I insert into an array — Dave Thomas <Dave@...> 2001/04/24

Jim Freeze <jim@freeze.org> writes:

[#14289] RCR: Array#insert — Shugo Maeda <shugo@...> 2001/04/27

At Wed, 25 Apr 2001 01:28:36 +0900,

[#14221] An or in an if. — Tim Pettman <tjp@...>

Hi there,

18 messages 2001/04/25

[#14267] Re: Ruby mascot proposal — "Conrad Schneiker" <schneik@...>

Danny van Bruggen,

16 messages 2001/04/26

[#14452] How to do it the Ruby-way 3 — Stefan Matthias Aust <sma@3plus4.de>

First a question: Why is

21 messages 2001/04/30

[ruby-talk:14400] RE: Does ruby have destructors that are easy to use?

From: "Benjamin J. Tilly" <ben_tilly@...>
Date: 2001-04-29 10:02:25 UTC
List: ruby-talk #14400
jfn@enteract.com (Jeremy Nelson) wrote:
>While helping a friend convert a program from perl to ruby, he wanted to
>know how to define a destructor for a ruby object.

Ruby doesn't have reliable destruction mechanics.

>We have already tried
>
>	define_finalizer(object, proc {....})
>
>but have observed that this has an unfortunate effect on performance.
>The program creates many tens of thousands of objects, and using the
>define_finalizer trick triples the time needed to run the program.
>Another problem is that it appears the finalizer function is called only
>when the object is garbage collected, and it does not seem to be known
>for certain that the garbage collector runs right away as soon as the
>last reference to an object is destroyed.

The garbage collector behaviour is as documented.  The
performance drop seems extreme to me.

>So my question is: is there a method that ruby calls when the last reference
>to an object is removed; a so called "destructor" in other object oriented
>languages?

No, because Ruby does not use reference counting.  Instead it
uses garbage collection.  The problem you are encountering is
true for all languages that use GC.  Reference counting lacks
this limit, but has a set of other things that tend to go
wrong.  (eg It doesn't handle circular references, it is much
harder to avoid the possibility of memory leaks.)

Alternate strategies:

1. Use an ensure block to do your cleanup actions in the
   calling code.
2. Have the object accept an iterator, and then it can
   manage its own lifecycle.
3. Implement your own reference counting on the objects
   that need it so you know when to clean things up.

FYI the decision to use GC rather than reference counting is
also coming up again in the Perl world.  Last I heard it was
not yet decided how Perl 6 will work.  (I have not been
listening that closely though.)  People want things (like
running in a JVM) that are incompatible with reference
counting, but people also don't want old code to break.

Cheers,
Ben

In This Thread

Prev Next