Quantcast
Channel: Forums - ArcObjects SDKs
Viewing all articles
Browse latest Browse all 1374

What is the best practise when using ComReleaser?

$
0
0
Coding gurus,

I've got a question about best practise when using the ComReleaser object. In the first example below is some stub code showing how I would typically using ComReleaser when I'm processing within a single loop.

Code:

Using comRel As New ComReleaser() 
  pFeatureCursor = pFeatureClass.Update(pQueryFilter, False)
  comRel.ManageLifetime(pFeatureCursor)
  pFeature = pFeatureCursor.NextFeature

  Do While Not pFeature Is Nothing
  ' Do something
pFeatureCursor.UpdateFeature(pFeature)
    pFeature = pFeatureCursor.NextFeature
  Loop
  pFeatureCursor.Flush()
End Using

Now suppose I want to loop through another cursor whilst looping through the first cursor, so nested. Is it appropriate to have a Using statement within a using statement (1) or do you simply add the inner cursor to the comReleaser object (2). I ask as I've not seen any examples and was wondering what was the best approach when nesting cursors?

Example 1


Code:

Using comRel As New ComReleaser() 
  pFeatureCursor = pFeatureClass.Update(pQueryFilter, False)
  comRel.ManageLifetime(pFeatureCursor)
  pFeature = pFeatureCursor.NextFeature

  Do While Not pFeature Is Nothing
  ' Do something
 
  Using comRel2 as New ComReleaser()
      pFeatureCursor2 = pFeatureClass2.Search(pQueryFilter2, False)
      comRel2.ManageLifetime(pFeatureCursor2)
      ' Do something inner looping stuff
End Using
  pFeatureCursor.UpdateFeature(pFeature)
    pFeature = pFeatureCursor.NextFeature
  Loop
  pFeatureCursor.Flush()
End Using

Example 2

Code:

Using comRel As New ComReleaser() 
  pFeatureCursor = pFeatureClass.Update(pQueryFilter, False)
  comRel.ManageLifetime(pFeatureCursor)
  pFeature = pFeatureCursor.NextFeature

  Do While Not pFeature Is Nothing
  ' Do something
    pFeatureCursor2 = pFeatureClass2.Search(pQueryFilter2, False)
      comRel.ManageLifetime(pFeatureCursor2)
    ' Do something inner looping stuff
  End Using
  pFeatureCursor.UpdateFeature(pFeature)
    pFeature = pFeatureCursor.NextFeature
  Loop
  pFeatureCursor.Flush()
End Using

In example 2 pFeatureCursor2 is added to comRel on every cycle of the outer cursor loop, is that good, bad or irrelevant?

Viewing all articles
Browse latest Browse all 1374

Trending Articles