2 Replies Latest reply on Oct 3, 2018 9:12 AM by Rick Davin

    PI AF SDK - FindElementsAttribute Memory Leak Issue


      Hi All,


      In my AF we have around 350 + Elements. To get all attributes, we are calling AFAttribute.FindElementAttributes method by passing element details (ie. FindElementAttributes method is called 350 times), which is currently consuming most of the RAM and Memory usage is not cleared after fetching all the attributes. Due to this, we are getting performance Issue and server is getting hanged. Can anyone help us providing the best way to search the attributes under an element if you have faced similar issue please?


      Code Snippet


      PIPointList pointList = new PIPointList();

      AFNamedCollectionList<AFElement> ElementList = AFElement.FindElementsByCategory(Analytics_AFDatabase

      , null

      , afdf

      , true

      , AFSortField.Name

      , AFSortOrder.Descending

      , 0

      , int.MaxValue

      , out totalElements);

      Log.Info("Total Elements found: " + totalElements); -> 350 Elements


      // Build the Attribute information for all elements

      Parallel.ForEach(ElementList, new ParallelOptions { MaxDegreeOfParallelism = 8 }, myelement =>


      // Find all of the attributes for Exception Calculation

      AFAttributeList myAttributes = AFAttribute.FindElementAttributes(Analytics_AFDatabase,














      // Create the structures and add them to the pointlist

      pointList.AddRange(CreateInfoStructures(myelement, myAttributes ));


          myAttributes .Clear();



      Thanks in advance.

        • Re: PI AF SDK - FindElementsAttribute Memory Leak Issue
          Dan Fishman


               I would recommend trying to use bulk queries and take advantage of AF queries that return multiple (Ienumerable<T>) results. You will find that executing parallel queries will keep the backend SQL server very busy and cause unnecessary network traffic.  I am not surprised that your parallel searches are causing performance issue given eight parallel threads!


          For many of the AF objects, the AF SDK will load them into memory; however, it typically isn't an issue.  I wonder if your pointList isn't getting freed up.  Also, there shouldn't be a need to call myAttributes.Clear().


          Take a look at the example here: AFElementSearch Class .

          One key part is to note is that full load is set to "true" causing the server to do more work initially and avoids additional RPC calls to the AF server.  If each elements had hundreds of attributes, you might have to try an alternative.  You can check each attribute and only process the attributes that meet you criteria.


          Also, I'd recommend looking here: AFAttributeSearch Class.  

          You could filter by attributes that meet your category criteria if you don't need to worry about element category.


          How many attributes do these elements typically have?  How often do you perform this search?  I also want bring this to the attention of OSIsoft search guru Rick Davin who can provide great advice and I'm sure can correct me!  The number of ways to search AF is a little overwhelming and takes experimenting!




          2 of 2 people found this helpful
          • Re: PI AF SDK - FindElementsAttribute Memory Leak Issue
            Rick Davin

            Hi Mohamed,


            What versions are you using for AF Server, Client, and PI Data Archive?


            Dan Fishman is correct.  Parallel is not needed and may actually degrade performance.  Bulk calls would be preferred as would an AFAttributeSearch if you have AF SDK 2.9.5 or later for both client and server.

            2 of 2 people found this helpful