From: Nat Pryce Date: 2002-12-09T19:56:05+09:00 Subject: Re: Ruminations... From: "Ted" >> | * 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 ________________________________ Dr. Nathaniel Pryce B13media Ltd. Studio 3a, Aberdeen Business Centre, 22/24 Highbury Grove, London, N5 2EA http://www.b13media.com