[GENERAL] [postgis-users] Union as an aggregate

strk strk at keybit.net
Wed Oct 1 11:08:20 PDT 2003


dblasby wrote:
> strk wrote:
> > Anyway - I'm not sure but I think that pfree'ing palloc'ed memory
> > in general might help in keeping memory usage under an acceptable
> > size. Don't know how postgres handles that exactly though ...
> 
> I agree here - always free that what you [m]alloc.  But, I've never 
> really seen postgresql leak memory.

I'm not talking about leaks here ... just intra-query memory usage.
For example during an aggregate run, palloced memory might grow
at each iteration without really needing it. More specifically
geometry passed to most postgis_geos function get DETOASTED resulting
in a (possible?) new (p)allocation which will not be (p)freed
`till the end of transaction. 

// this happens at the top of most functions
GEOMETRY *geom1 = (GEOMETRY *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
// now *geom1 could point to a newly allocated area or not ...
// before exiting, we can call 
if ( (Pointer) geom1 != PG_GETARG_DATUM(0) ) pfree(geom1);
// so that in case of no new allocation no action is taken

--strk;



More information about the postgis-users mailing list