OmniDriver Memory Management in Delphi
Our general-purpose OmniDriver device driver allows you to control spectrometers and collect spectra using Delphi, the popular Object-Pascal system from Embarcadero (formerly Borland).
Some customers have noted that memory usage seems to climb when calling Delphi from OmniDriver, which can raise fears of a potential memory leak. The solution is to make sure you call SafeArrayDestroy on every PSafeArray as soon as you are finished processing the result — and definitely before you try reusing the same object.
This will ensure Delphi “marks” the memory in our .NET driver as free to be released. Note that the memory won’t be immediately released — .NET has its own internal schedule for reclaiming marked memory, and it will collectively release all marked segments at the next scheduled interval.
If you monitor this sequence in a process manager, you should see that memory size climbs over time as you continue to take acquisitions, and then will sharply drop as GC kicks in; this cycle will repeat over the runtime of your application, creating a “sawtooth” pattern. This is correct and normal, and indicative that everything is working as expected.