Do I need to release each object? Is some memory management handled for me?
ArcObjects – Rules for Releasing from Memory in .NET
arcgis-enginearcobjects
Related Solutions
There is a VBA sample in the ArcDesktop help How to add a balloon callout it should be possible to customize for ArcGIS Engine, Change so that you ues the ActiveView from your MapControl or PagelayoutControl.
Update, code that works in engine:
Private Sub AddBalloonCallout(ByVal activeView As IActiveView)
Dim pTextElement As ITextElement
Dim pElement As IElement
Dim pPoint As IPoint
Dim pCallout As ICallout
Dim pTextSymbol As IFormattedTextSymbol
Dim pGraphicsContainer As IGraphicsContainer
Dim midX As Double, midY As Double
'Create a new text element
pTextElement = New TextElement
pElement = CType(pTextElement, IElement) 'QI
pTextElement.Text = "Text callout" & vbCrLf & "In the middle of the screen"
'Position the new element on the active view's center point
midX = (activeView.Extent.XMax + activeView.Extent.XMin) / 2
midY = (activeView.Extent.YMax + activeView.Extent.YMin) / 2
pPoint = New Point
pPoint.PutCoords(midX, midY)
pElement.Geometry = pPoint
'Set the text element symbology to a default balloon callout
pTextSymbol = New TextSymbol
pCallout = New BalloonCallout
pTextSymbol.Background = CType(pCallout, ITextBackground)
'Use this formula to get a callout anchor point location
pPoint.PutCoords(midX - activeView.Extent.Width / 4, midY + activeView.Extent.Width / 20)
pCallout.AnchorPoint = pPoint
pTextElement.Symbol = pTextSymbol
'Add the element to the active view, either the focus Map or PageLayout
pGraphicsContainer = CType(activeView, IGraphicsContainer)
pGraphicsContainer.AddElement(pElement, 0)
pElement.Activate(activeView.ScreenDisplay)
'Flag the area of the new element for refreshing
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pElement, Nothing)
End Sub
When you create your featureclass, try using an InMemoryWorkspaceFactory instead of a ShapefileWorkspaceFactory. See code here.
Best Answer
Most notably, always explicitly release cursors when you are done with them. I also release some enumeration objects which imply database access, for example IEnumRelationship you get from IRelationshipClass.GetRelationshipsForObject.
Also, when you create a lot of COM instances which are short-lived (especially in tight loops), it is also a good idea to release them explicitly.
There are also scenarios when is it advisable to release individual feature (row) references. For example, if you create a new geodatabase version, edit data, reconcile&post, attempts to delete the version afterwards might fail since there might be unreleased rows, which in turn keep reference to the version (workspace) you are trying to delete. Mostly, though, such scenarios are rare and you do not need to account for them in your day-to-day ArcObjects development. It would only make the code cluttered with extraneous cleanup, making it less maintainable.
It is also important to say when not to release .NET wrappers - never explicitly release RCW of ArcObjects which might be in use by any other managed code. One example of this - do not release IMap when in ArcMap. In general, do not try to release ArcObjects which you did not create.