Programming with Framework EDI .NET Hybrid
Dispose

The Dispose method is the standard .NET method of explicitly notifying the .NET object to release its data.  It is available in all FREDI .NET classes.

Syntax:

Remarks:

It is not necessary to call this method because the .NET garbage collector will eventually release the data when it frees objects.  However, when using FREDI .NET hybrid, this method should be called when the object is no longer used.  FREDI .NET hybrid is managed code wrapping unmanaged code, so while the .NET garbage collector frees the managed objects, the unmanaged resources are not.  The unmanaged resources in  FREDI are released when the client notifies the object that is no longer in use by calling the Dispose() method.

Example:

Dim oSchemas As ediSchemas
Dim oSchema As ediSchema
Dim oSegment As ediDataSegment
Dim oEdiDoc As ediDocument

' Create instance of Framework EDI.
oEdiDoc = New ediDocument

oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly

' Disable standard reference library.
oSchemas = oEdiDoc.GetSchemas
oSchemas.EnableStandardReference = False

oSchema = oEdiDoc.LoadSchema(AppDomain.CurrentDomain.BaseDirectory & "SampleSefX12_850.SEF", 0)

' Load EDI document normally.
oEdiDoc.LoadEdi(AppDomain.CurrentDomain.BaseDirectory & "SampleEdiX12_850.X12")

oSegment = oEdiDoc.FirstDataSegment

While Not oSegment Is Nothing

    Dim sSegmentID As String
    Dim sArea As String
    Dim sLoopSection As String
    Dim oSegment2 As ediDataSegment

    sSegmentID = oSegment.ID
    sArea = oSegment.Area
    sLoopSection = oSegment.LoopSection


    ' Explcitly call the Dispose method to let FREDI know
    ' that the client no longer uses the old oSegment data.

    ' Store new data returned by oSegment.Next
    oSegment2 = oSegment.Next

    ' Let FREDI know data in oSegment is no longer used
    oSegment.Dispose()

    ' Replace data in oSegment with new data
    oSegment = oSegment2

End While

oEdiDoc.Dispose()

Samples