ForceGarbageCollection

PROPERTY - Read / Write

Parent Object - HL7Vendor


Name: ForceGarbageCollection

Data Type: Boolean (Default TRUE)

Description: Get / Set the ForceGarbageCollection boolean property.

 

Further: When creating HL7 applications using the EasyHL7 Managed Code objects it is a pretty common scenario to reuse objects iteratively. This is particularly true when processing large batches of HL7 messages (see the example below). If the ForceGarbageCollection property is TRUE (it's default value) the HL7Vendor Object will periodically (if needed) suspend the current thread to allow the .Net Framework Garbage Collector to empty it's queue by calling the WaitForPendingFinalizers() method of the .Net GC object. It will also force a complete garbage collection whenever the Refresh() method is called and when the object is destroyed and it's finalizer is invoked by regular .Net Framework garbage collection. You can override all of this behavior by setting the ForceGarbageCollection property to False.

 

Why is this necessary? At the time of this writing (January 2009) there is a little known bug in the .Net Framework Garbage Collecting subsystem which affects systems running more than 2 GB RAM (and typically Windows Server 2003 or greater, both 32 and 64 bit versions) which can cause a NULL memory exception to be thrown IN ERROR when the GC memory heap reaches a certain size. Basically what happens is that the GC queries the system for available memory to use for discarded objects and is told there is plenty of memory available (which is true) but then throws the error when it tries to allocate memory on the GC heap.

 

Example Highly Iterative Code

 

Dim nResult As EasyHL7MC40.HL7FileAnalyzer.EHFA_ErrorType

Dim myAnalyzer As EasyHL7MC40.HL7FileAnalyzer

Dim oHL7 As EasyHL7MC40.EasyHL7Message

Dim oSegment As EasyHL7MC40.HL7MessageSegment

Dim Idx As Long

 

MyAnalyzer = oVendor.NewFileAnalyzer()

With MyAnalyzer

nResult = .AnalyzeHL7File("C:\HL7\Example50000Messages.hl7")

If nResult <> EHFA_NoError Then

  'Note - Check the result for more info

  Exit Sub

End If

For Idx = 1 To .FileMessageCount

  oHL7 = .GetHL7MessageObject(Idx)

  With oHL7

     If .SegmentExists("PID") Then

        oSegment = .GetSegment("PID")

        '...Process PID Segment

        '...

        '...

     End If

  End With

  oSegment = Nothing

  oHL7 = Nothing  

'.NOTE the highly iterative nature. oHL7 and oSegment

'are destroyed and reused <nnnn> times.

Next

End With