This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Memory leaks in compiler


On Thu, Jan 17, 2008 at 11:08:25AM -0500, Ross Ridge wrote:
> Diego Novillo wrote:
> >I agree.  Freeing memory right before we exit is a waste of time.
> 
> Dave Korn writes:
> > So, no gcc without an MMU and virtual memory platform ever again?
> >Shame, it used to run on Amigas.
> 
> I don't know if GCC ever freed all of its memory before exiting.
> An operating system doesn't need an MMU or virtual memory in order to
> free all the memory used by a process when it exits.  MS-DOS did this,
> and I assume AmigaOS did as well.

valgrind will not report a heap block as a leak if it is pointed to by
a global or static pointer.  So if you want to shut up valgrind (and other leak
detectors that work based on reachability, like Purify), then instead
of doing a "free" (or delete, or other deallocation call) at the end,
you could just assign a pointer to the top of the data structure to
some global pointer that you reserve for the purpose.  So, instead
of

	dealloc_big_object(obj_ptr);

just

	static T* shut_up_valgrind;
	shut_up_valgrind = obj_ptr;

valgrind can also give you a report of how much memory remains allocated
on exit, but that is a separate issue.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]