[m-dev.] for review: fix memory leak

Mark Anthony BROWN dougl at cs.mu.OZ.AU
Tue Oct 5 12:46:24 AEST 1999


Fergus Henderson writes:
> 
> Estimated hours taken: 16
> 
> Fix a problem where the compiler was leaking memory
> when compiling more than one file a time.
> Note that this fix solves that specific bug,
> but does not address the problem in general.

If you are going to mention that there is a general problem,
could you give some more details on what the general problem is?

> (A more general fix would be for the garbage collector
> to scan only the parts of the Mercury stacks which
> are currently live, but this is trickier...)
> 
> The fix includes adding a new library module library/gc.m.

The new module should be mentioned in NEWS.

> 
> compiler/mercury_compile.m:
> 	If we're processing more than one module, then invoke garbage
> 	collection explicitly after processing each one.
> 
> library/gc.m:
> 	New module.  Currently this only contains one routine,
> 	`garbage_collect', which forces a garbage collection.
> 	This routine clears out the Mercury stacks and registers
> 	before invoking GC_gcollect().
> 
> 	Eventually we might want to include a more extensive interface,
> 	including e.g. features to enable and disable collection, etc.
> 	(see boehm_gc/gc.h for a list of useful features).
> 
> runtime/mercury_regs.h:
> 	Add macro MR_clear_regs_for_GC(), for use by gc__garbage_collect.
> 
> runtime/mercury_memory_zones.h:
> 	Add macro MR_clear_zone_for_GC(), for use by gc__garbage_collect.
> 

> Index: library/gc.m
> ===================================================================
> RCS file: gc.m
> diff -N gc.m

> +% This module defines some procedures for controlling the actions
> +% of the garbage collector.
> +%
> +% ---------------------------------------------------------------------------%
> +% ---------------------------------------------------------------------------%

Just a quibble, but I think
s/% --/%---/

I'll leave it up to you whether to change this or not.

> Index: runtime/mercury_memory_zones.h
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/runtime/mercury_memory_zones.h,v
> retrieving revision 1.4

> +** MR_clear_zone_for_GC(MemoryZone *zone, void *start_address):
> +**	Zero out the (hopefully unused) portion of the zone
> +**	from the specified `start_address' to the end of the zone.
> +**	This is used to avoid unwanted memory retition due to 

retition?

> Index: runtime/mercury_regs.h
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/runtime/mercury_regs.h,v

>  /*
> +** MR_clear_regs_for_GC() clears all of the Mercury general-purpose
> +** registers.  It is used to avoid unwanted memory retition due to

Ditto.

I see no other problems with this change.

Cheers,
Mark
-- 
Mark Brown, PhD student            )O+  |  "Another of Fortran's breakthroughs
(m.brown at cs.mu.oz.au)                   |  was the GOTO statement, which was...
Dept. of Computer Science and Software  |  uniquely simple and understandable"
Engineering, University of Melbourne    |              -- IEEE, 1994
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list