<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ConstructUnion runs out of memory in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/constructunion-runs-out-of-memory/m-p/116774#M3054</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Joseph,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've never had any problems with the ConstructUnion method. So after reading your thread I knocked together the following VBA code to test it. I was able to run it without error on 40K and 60K polygons.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This suggests to me that it may be an issue with your input data? Have you run it through the check geometry tool first to see if there are any offending polygons?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Public Sub Test()
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Get layer
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Dim pMXDocument As IMxDocument
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pMXDocument = ThisDocument
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pMap As IMap
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pMap = pMXDocument.FocusMap
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pLayer As ILayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pLayer = pMap.Layer(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pFeatureLayer As IFeatureLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeatureLayer = pLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Get the 40,000 selected polygons
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Dim pFeatureSelection As IFeatureSelection
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeatureSelection = pFeatureLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pSelectionSet As ISelectionSet
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSelectionSet = pFeatureSelection.SelectionSet
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Print pSelectionSet.Count
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Create cursor over selection
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Dim pCursor As ICursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; pSelectionSet.Search Nothing, False, pCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pRow As IRow
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRow = pCursor.NextRow
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pPolygon As IPolygon
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pGeometryBag As IGeometryBag
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeometryBag = New GeometryBag
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pSpatialReference As ISpatialReference
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pGeoDataset As IGeoDataset
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeoDataset = pFeatureLayer.FeatureClass
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSpatialReference = pGeoDataset.SpatialReference
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeometryBag.SpatialReference = pSpatialReference
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pGeometryCollection As IGeometryCollection
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeometryCollection = pGeometryBag
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Add polygons to bag
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Debug.Print "Adding to geometry bag"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Do While Not pRow Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pPolygon = pRow.Value(pRow.Fields.FindField("Shape"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pGeometryCollection.AddGeometry pPolygon
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRow = pCursor.NextRow
&amp;nbsp;&amp;nbsp;&amp;nbsp; Loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Print "done looping"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Do the union
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Dim pTopoOp As ITopologicalOperator
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pTopoOp = New Polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pEnumGeometry As IEnumGeometry
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pEnumGeometry = pGeometryBag
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Print CStr(pEnumGeometry.Count) &amp;amp; " in bag"
&amp;nbsp;&amp;nbsp;&amp;nbsp; pEnumGeometry.Reset
&amp;nbsp;&amp;nbsp;&amp;nbsp; pTopoOp.ConstructUnion pEnumGeometry
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Print "Got here with out error!"
End Sub
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using ArcGIS 10.1, Windows 7, 4GB Ram.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:51:49 GMT</pubDate>
    <dc:creator>DuncanHornby</dc:creator>
    <dc:date>2021-12-11T06:51:49Z</dc:date>
    <item>
      <title>ConstructUnion runs out of memory</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/constructunion-runs-out-of-memory/m-p/116773#M3053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I create a geometry bag and added 40k or so polygon features into it using the geometry collection interface.&amp;nbsp; All-together, adding geometries brings my memory stamp up to roughly 520MB or so.&amp;nbsp; After this, I create an empty polygon and use the topological operator to ConstructUnion against this geometry bag.&amp;nbsp; This operation spins for 20 seconds or so, then the memory stamp increases without bound, crashing my process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I originally modified my code to use ConstructUnion instead of multiple Unions, since I saw a noticable performance increase.&amp;nbsp; Unfortunately, it looks like construct union has some type of sporaddic memory leak.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Questions and comments welcome!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2013 13:46:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/constructunion-runs-out-of-memory/m-p/116773#M3053</guid>
      <dc:creator>JosephArmbruster</dc:creator>
      <dc:date>2013-06-12T13:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: ConstructUnion runs out of memory</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/constructunion-runs-out-of-memory/m-p/116774#M3054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Joseph,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've never had any problems with the ConstructUnion method. So after reading your thread I knocked together the following VBA code to test it. I was able to run it without error on 40K and 60K polygons.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This suggests to me that it may be an issue with your input data? Have you run it through the check geometry tool first to see if there are any offending polygons?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Public Sub Test()
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Get layer
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Dim pMXDocument As IMxDocument
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pMXDocument = ThisDocument
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pMap As IMap
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pMap = pMXDocument.FocusMap
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pLayer As ILayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pLayer = pMap.Layer(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pFeatureLayer As IFeatureLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeatureLayer = pLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Get the 40,000 selected polygons
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Dim pFeatureSelection As IFeatureSelection
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeatureSelection = pFeatureLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pSelectionSet As ISelectionSet
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSelectionSet = pFeatureSelection.SelectionSet
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Print pSelectionSet.Count
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Create cursor over selection
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Dim pCursor As ICursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; pSelectionSet.Search Nothing, False, pCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pRow As IRow
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRow = pCursor.NextRow
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pPolygon As IPolygon
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pGeometryBag As IGeometryBag
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeometryBag = New GeometryBag
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pSpatialReference As ISpatialReference
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pGeoDataset As IGeoDataset
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeoDataset = pFeatureLayer.FeatureClass
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pSpatialReference = pGeoDataset.SpatialReference
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeometryBag.SpatialReference = pSpatialReference
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pGeometryCollection As IGeometryCollection
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pGeometryCollection = pGeometryBag
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Add polygons to bag
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Debug.Print "Adding to geometry bag"
&amp;nbsp;&amp;nbsp;&amp;nbsp; Do While Not pRow Is Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pPolygon = pRow.Value(pRow.Fields.FindField("Shape"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pGeometryCollection.AddGeometry pPolygon
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pRow = pCursor.NextRow
&amp;nbsp;&amp;nbsp;&amp;nbsp; Loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Print "done looping"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; &lt;SPAN style="color:#008000;"&gt;' Do the union
&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; Dim pTopoOp As ITopologicalOperator
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pTopoOp = New Polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pEnumGeometry As IEnumGeometry
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pEnumGeometry = pGeometryBag
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Print CStr(pEnumGeometry.Count) &amp;amp; " in bag"
&amp;nbsp;&amp;nbsp;&amp;nbsp; pEnumGeometry.Reset
&amp;nbsp;&amp;nbsp;&amp;nbsp; pTopoOp.ConstructUnion pEnumGeometry
&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Print "Got here with out error!"
End Sub
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using ArcGIS 10.1, Windows 7, 4GB Ram.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:51:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/constructunion-runs-out-of-memory/m-p/116774#M3054</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2021-12-11T06:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: ConstructUnion runs out of memory</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/constructunion-runs-out-of-memory/m-p/116775#M3055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No issues reported by Check Geometry.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note: I am running on Arc10.1 sp1, windows 7.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 11:37:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/constructunion-runs-out-of-memory/m-p/116775#M3055</guid>
      <dc:creator>JosephArmbruster</dc:creator>
      <dc:date>2013-06-13T11:37:05Z</dc:date>
    </item>
  </channel>
</rss>

