> * The "routine" has more than one exit. This violates the "one entry, one exit" rule of structured programming.
I don't care about that principle. It's no good.
matz.
IS TOO!!!! Where do memory leaks come from? <bg>
> * The "routine" has more than one exit. This violates the "one entry, one exit" rule of structured programming.
I don't care about that principle. It's no good.
matz.
IS TOO!!!! Where do memory leaks come from? <bg>
- The “routine” has more than one exit. This violates the “one entry,
one exit” rule of structured programming.I don’t care about that principle. It’s no good.
matz.
IS TOO!!! Where do memory leaks come from?
From languages with no GC…
Hal
----- Original Message -----
From: “Ted” ted@datacomm.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org; matz@ruby-lang.org
Cc: ruby-talk@ruby-lang.org; “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Sunday, December 08, 2002 10:49 PM
Subject: Re: Ruminations…
- The “routine” has more than one exit. This violates the “one entry,
one exit” rule of structured programming.I don’t care about that principle. It’s no good.
matz.
IS TOO!!! Where do memory leaks come from?
Quick answer: from languages with no support for automatic reclamation of
resources.
Long answer: it doesn’t matter if a routine returns from multiple points if
resources are automatically reclaimed either by GC or by other means. C++
uses destructors of objects on the stack. Ruby uses blocks.
E.g. The method below has multiple exit points, but no matter which exit
point is reached, the GC will collect the object referenced by the variable
lots_of_data, and the File.open method will close the stream.
def my_method( filename, foo )
File.open( filename ) do |stream|
lots_of_data = read_lots_of_data_from_stream(stream)
if foo
return lots_of_data
else
return nil
end
end
end
From: “Ted” ted@datacomm.com
Dr. Nathaniel Pryce
B13media Ltd.
Studio 3a, Aberdeen Business Centre, 22/24 Highbury Grove, London, N5 2EA
http://www.b13media.com