[geos-commits] r2196 - in trunk/source: headers/geos/noding noding
svn_geos at osgeo.org
svn_geos at osgeo.org
Sat Oct 4 14:14:09 EDT 2008
Author: pramsey
Date: 2008-10-04 14:14:09 -0400 (Sat, 04 Oct 2008)
New Revision: 2196
Modified:
trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h
trunk/source/noding/MCIndexSegmentSetMutualIntersector.cpp
Log:
Memory leak fix for prepared geometry, from Hartmut Kaiser. (#207)
Modified: trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h
===================================================================
--- trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h 2008-09-29 19:24:06 UTC (rev 2195)
+++ trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h 2008-10-04 18:14:09 UTC (rev 2196)
@@ -98,7 +98,11 @@
int processCounter;
// statistics
int nOverlaps;
-
+
+ // memory management helper
+ typedef std::vector<std::vector<index::chain::MonotoneChain*>*> chainstore_mm_type;
+ chainstore_mm_type chainStore;
+
void addToIndex( SegmentString * segStr);
void intersectChains();
Modified: trunk/source/noding/MCIndexSegmentSetMutualIntersector.cpp
===================================================================
--- trunk/source/noding/MCIndexSegmentSetMutualIntersector.cpp 2008-09-29 19:24:06 UTC (rev 2195)
+++ trunk/source/noding/MCIndexSegmentSetMutualIntersector.cpp 2008-10-04 18:14:09 UTC (rev 2196)
@@ -39,25 +39,14 @@
std::vector<MonotoneChain*>* segChains = 0;
segChains = MonotoneChainBuilder::getChains(segStr->getCoordinates(), segStr);
+ chainStore.push_back(segChains);
+
for (std::size_t i = 0, n = segChains->size(); i < n; i++)
{
MonotoneChain * mc = (*segChains)[i];
mc->setId(indexCounter++);
index->insert(mc->getEnvelope(), mc);
}
-
- // FIXME - BWJ: seems to cause some tests of prepared predicates to fail, but leaving
- // this out probably causes a memory leak. more research needed
- //
- // NOTE - mloskot: segChains can not be deleted because index composed above will later
- // use (refer to) MonotoneChain objects, elements originally stored in segChains collection.
- // However, then segChains allocated by MonotoneChainBuilder::getChains gets never deallocated,
- // so memory leaks. This looks like a design bug and not-synchronized lifetime of related objects.
- // This bug really seems not to be easy to fix.
- //
- //for (std::vector<MonotoneChain*>::iterator it = segChains->begin(), e = segChains->end(); it != e; ++it)
- // delete *it;
- //delete segChains;
}
void
@@ -90,14 +79,14 @@
std::vector<MonotoneChain*>* segChains = 0;
segChains = MonotoneChainBuilder::getChains(segStr->getCoordinates(), segStr);
+ chainStore.push_back(segChains);
+
for (std::size_t i = 0, ni = segChains->size(); i < ni; i++)
{
MonotoneChain* mc = (*segChains)[i];
mc->setId( processCounter++ );
monoChains->push_back(mc);
}
-
- delete segChains;
}
//
@@ -116,11 +105,19 @@
MCIndexSegmentSetMutualIntersector::~MCIndexSegmentSetMutualIntersector()
{
delete index;
- for (std::size_t i = 0, ni = monoChains->size(); i < ni; i++ )
- {
- delete (*monoChains)[ i ];
- }
delete monoChains;
+
+ chainstore_mm_type::iterator end = chainStore.end();
+ for (chainstore_mm_type::iterator it = chainStore.begin(); it != end; ++it)
+ {
+ typedef std::vector<index::chain::MonotoneChain*> chainstore_type;
+ chainstore_type::iterator csend = (*it)->end();
+ for (chainstore_type::iterator csit = (*it)->begin(); csit != csend; ++csit)
+ {
+ delete *csit;
+ }
+ delete *it;
+ }
}
void
More information about the geos-commits
mailing list