We recently built two applications leveraging the PI SDK, and I am curious to learn more about best practices related to garbage collection to optimize memory usage in the contexts of the applications we built.
The first application is a command line VB.NET application using the PI SDK to retrieve either the current value or multiple historical values for a number of tags (the data retrieval method is dependent on how an associated XML configuration file is configured). The application runs periodically using the Windows Task Scheduler. Each time the application runs, it retrieves the aforementioned data for tags specified in the config file and posts that data to a web service. To do so, we are leveraging the .GetPoints method and .Data.Snapshot or .Data.RecordedValues methods. We are wondering if garbage collection (i.e., GC.Collect) and setting the retrieved value/values variable to "Nothing" (e.g., val = Nothing, where val is a PIValue variable) would be best practice/helpful during code execution, considering we are looping through and retrieving data for a potentially large number of tags. On the other hand, we are reusing the same variable during the code execution and from what I've read, .NET handles garbage collection automatically, so I am curious to hear what peoples' thoughts are on this.
The second application is a VB.NET ACE application which retrieves instantaneous values for the input PI tags/aliases, passes them to a third-party DLL which returns some values, and outputs the values returned by the third-party DLL to the output PI tags/aliases. With this application, we have observed that when we initially start the calculation using the PI ACE Manager, the associated PIACEClassLibraryHost.exe process consumes ~16 MB of memory, but within just a few hours, that number grows to several hundred MBs and eventually up to ~1.5 GB. After some indeterminable and inconsistent time, the calculation stops working (that is, no more outputs are generated) and a generic error message ("External component has thrown an exception”) appears in the PI message log. Meanwhile, other ACE calculations continue working. We are wondering if the reason the ACE process stops working is because no garbage collection/"unloading" of the third-party DLL is being performed, and if so, how this could best be handled.
I appreciate any insights people can share