AnsweredAssumed Answered

What is the best practise when using ComReleaser?

Question asked by Hornbydd Champion on Jan 23, 2013
Latest reply on Jan 28, 2013 by rfairhur24
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.

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


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

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?

Outcomes