[GENERAL] [postgis-users] Union as an aggregate
David Blasby
dblasby at refractions.net
Wed Oct 1 10:04:07 PDT 2003
strk wrote:
> postgis_geos_wrapper.cpp: GEOSGeometryType(Geometry *g1)
> returns malloced memory.
>
> postgis_geos.c: GEOS2POSTGIS()
> calls GEOSGeometryType and never frees returned value.
I caught both of these and fixed them yesterday. They dont leak very
much memory, so this isnt the cause of your problem.
I sent a test program off to yuri that causes GEOS to leak badly. I
think his GEOS fix will solve your leak. Hopefully he'll fix and commit
it this week.
> I've seen many malloc calls in postgis_geos_wrapper,
> would palloc be more appropriate there ?
Perhaps, but I wanted postgis_geos_wrapper.cpp to be independent of
postgresql. I think you'll find that all this memory is freed, except
under some weird error conditions. I can fix those.
> 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.
For example, this query should be leaking 320mb of memory, but in actual
fact, it doesnt appear to be leaking anything.
BEGIN;
cwb_wsa50_test=# select sum(mem_size(geom)) from wsa_lakes ;
sum
-----------
317974844
(1 row)
END;
From the postgresql manual:
"When allocating memory, use the PostgreSQL routines palloc and pfree
instead of the corresponding C library routines malloc and free. The
memory allocated by palloc will be freed automatically at the end of
each transaction, preventing memory leaks."
Other parts of the documentation say that it will be automatically
pfree()-ed at the end of each call.
More information about the postgis-users
mailing list