[geos-devel] Memory Leak In GEOSIntersection_r
Mick Orridge
m.orridge at gismosoftware.co.uk
Fri Jan 23 16:41:28 PST 2015
This is my first post here, so feel free to let me know if I should be
doing things differently.
I've been using the nightly snapshot from 4/1/2015 to generate Voronoi
polygons and then clip them to the UK coastline on Windows 8.1 with
VS2013. After processing several 100,000 polygons with
GEOSIntersection_r my laptop was running out of memory.
I've investigated further and it looks like the Edges rejected by
OverlayOp::insertUniqueEdges in OverlayOp.cpp are not being deleted.
My, not very elegant, solution to fix this is to add a new method to
OverlayOp as follows:-
void
OverlayOp::deleteOrphanedEdges(vector<Edge*> *edges, const Envelope *env)
{
for (size_t i = 0, n = edges->size(); i < n; ++i)
{
Edge *e = (*edges)[i];
if (env && !env->intersects(e->getEnvelope())) delete e;
}
}
and then call this just before exiting the method
OverlayOp::computeOverlay(OverlayOp::OpCode opCode)
I don't really understand enough about the data structures to know if
this is a valid fix or not. If somebody who does understand how this
works could have a look at things I'd appreciate it.
There is also a small memory leak of a geomFactory in init/finishGEOS().
The only way I can see to fix this is to introduce a reference count and
then null the static pointer when it reaches 0. Happy to have a look at
fixing this if this seems a reasonable approach.
Regards,
Mick Orridge
More information about the geos-devel
mailing list