How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?

Malcolm McLean malcolm.mclean5 at btinternet.com
Mon Aug 16 13:20:22 CEST 2010


On Aug 16, 10:20 am, Standish P <stnd... at gmail.com> wrote:
> [Q] How far can stack [LIFO] solve do automatic garbage collection and
> prevent memory leak ?
>
Most programs can be written so that most of their memory allocations
are matched by destructors at the same level.

However the allocations that can't be written this way typically tend
to be the small frequently-called ones used for nodes in dynamic graph
objects, or small resizeable buffers to hold strings and the like.
This is where you get the performance hit with repeated calls to
malloc() and free().

So generally it's not worthwhile writing a stack allocator for a
normal program. That's not to say there aren't a few individual cases
where it can help performance. (See the chapter "Memory games" in my
book Basic Agorithms for details about memory allocation strategies).





More information about the Python-list mailing list