Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#342 closed defect (fixed)

Prepared MultiPolygon predicates leak memory

Reported by: olt Owned by: sgillies
Priority: minor Milestone: 3.3.0
Component: Default Version: main
Severity: Annoyance Keywords: memory leak, prepared geometries, multipolygon
Cc: olt@…

Description

Using prepared binary predicates like 'contains' with MultiPolygons leaks memory. I have tested it with 3.1.1, 3.2.0 (using Shapely, which uses the C API) and latest trunk (r2982) with the attached C test program. So it might be a C API only bug.

The test program does not leak if the predicate is called directly with the MultiPolygon (no prepared geometry) or if the prepared geometry is only a polygon.

Attachments (1)

memleak_mp_prep.c (630 bytes ) - added by olt 14 years ago.
Test program to demonstrate memory leak

Download all attachments as: .zip

Change History (9)

by olt, 14 years ago

Attachment: memleak_mp_prep.c added

Test program to demonstrate memory leak

comment:1 by sgillies, 14 years ago

Owner: changed from geos-devel@… to sgillies
Status: newassigned

comment:2 by sgillies, 14 years ago

Priority: majorminor
Severity: UnassignedAnnoyance

Leaks and valgrind both say no leaks, but the footprint of the prepared geometry does grow. Looks like it's accumulating data as contains() is called.

comment:3 by strk, 13 years ago

3.2.2 fixed context leaks can you still see the leak with that version ?

comment:4 by olt, 13 years ago

No. Just recompiled the test program and it still leaks memory.

% gcc memleak_mp_prep.c -o memleak_mp_prep -L../tmp/geos-3.2.2/capi/.libs/ -lgeos_c
% DYLD_LIBRARY_PATH=../tmp/geos-3.2.2/capi/.libs:../tmp/geos-3.2.2/source/.libs ./memleak_mp_prep

comment:5 by olt, 13 years ago

Ok. I did some testing with a profiler and there are a lot of malloc calls from MCIndexSegmentSetMutualIntersector. Further testing shows that chainStore is growing infinite.

comment:6 by strk, 13 years ago

I can confirm the analisys. Will look for a possible workaround. We have no garbage collector so must find out when it is safe to cleanup.

comment:7 by strk, 13 years ago

Milestone: 3.3.0
Resolution: fixed
Status: assignedclosed

Fixed in r3357. Thanks for not letting this issue fade away.

comment:8 by olt, 13 years ago

Great. I tested it with trunk again and it looks like it was the only leak, since memory is now constant.

Note: See TracTickets for help on using tickets.