http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48481
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-04-07 12:16:23 UTC --- Haven't bootstrapped/regtested it, but it is definitely improvement. With N=1000 and N=2000 the generated assembly is identical, for N=1000 reported TOTAL went down from 432768 kB to 89362 kB, for N=2000 from 1672544 kB to 298232 kB and on a box with 8GB of RAM I can compile even N=5000 case, which takes 1685817 kB reported TOTAL memory. N=10000 requires already too much RAM though. In the -DN=5000 -fmem-report dump the only interesting allocations are: cp/tree.c:1447 (ovl_cons) 1600160000:97.9% 0: 0.0% 1280032: 2.0% 0: 0.0% 50045001 Total 1634296366 38329920 65115511 11401989 51377483 source location Garbage Freed Leak Overhead Times so if even that garbage could be freed, this would be fixed completely. Even for N=1000 ovl_cons is the only one that really matters: cp/tree.c:1447 (ovl_cons) 64032000:90.2% 0: 0.0% 256032: 1.8% 0: 0.0% 2009001 Total 71012606 8986384 14294815 2724053 2289400 source location Garbage Freed Leak Overhead Times Those ovl_cons calls are from lookup_arg_dependent -> ... -> add_function -> build_overload. Is it guaranteed that perform_koenig_lookup, if it returns a chain of OVERLOADs, all OVERLOADs have been freshly make_noded and aren't shared with anything else? If yes, perhaps we could afterwards ggc_free the chain, or move it to some cache of OVERLOAD nodes and make ovl_cons start from that cache.