From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,345a8b767542016e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-14 12:43:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!ppp-4-214.5800-11.telinco.NET!not-for-mail From: Nick Roberts Newsgroups: comp.lang.ada Subject: Re: memory leakages with Ada? Date: Thu, 14 Mar 2002 20:42:56 +0000 Message-ID: <3C910B50.2030208@callnetuk.com> References: <3c90af1e@news.starhub.net.sg> NNTP-Posting-Host: ppp-4-214.5800-11.telinco.net (212.1.155.214) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1016138582 17473723 212.1.155.214 (16 [25716]) User-Agent: Mozilla/5.0 (Windows; U; Win95; en-GB; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: en-gb Xref: archiver1.google.com comp.lang.ada:21248 Date: 2002-03-14T20:42:56+00:00 List-Id: Larry Kilgallen wrote: >In article <3c90af1e@news.starhub.net.sg>, "Calvin Ow" writes: > >>Has Ada got any memory leakage problems like that of C? >> > >Ada95 has several additional capabilities to guard against memory leaks. > Someone correct me if I'm wrong, but I think it would be more correct to put it this way: the Ada language makes provision for an implementation to provide garbage collection. If an Ada program is compiled/executed under an implementation that provides garbage collection, then this counts as a 'capability to guard against memory leaks'. If it provides _full_ garbage collection, this will normally provide complete protection against memory leaks. However, all this is slightly academic, as (I am given to believe) there are no Ada implementations that provide garbage collection (apart from the ones which target the JVM, which is a somewhat different billie-can of anchovies anyway). Without GC, dynamic allocation will cause memory leakage (in the generally accepted meaning) unless: unused memory is freed explicitly (by the use of Unchecked_Deallocation); or, the algorithm uses (or tends to use) all or most dynamically allocated objects up until the end of the scope of the relevant access type's declaration (usually the end of the program's execution). This is pretty much the same situation as with C. Of course, memory leakage can also be caused, in any programming language, by: faults in the compiler; programs doing low-level things, and getting it wrong. Typically, utility libraries which provide 'containers' will need to do a lot of explicit freeing of memory; a bug can easily cause memory leakage. >It is possible to bypass most checks in Ada, so one could encounter >just as much trouble in Ada if one attempted to transliterate a C >program into Ada while retaining every aspect of the C design. > >>Especially with the use of Pragma calls to C? >> > >If you call from Ada to C, the portion that is written in C is >fully empowered to leak all the memory it wants :-) Thus the >question of memory leaks when doing that boils down to an >issue of whether the C code is well written. > Note that there are plenty of other kinds of problems associated with memory management that Ada (both the standard language and typical implementations) provides good protection against, and C does not.