Showing results 1 to 3 of 3

Thread: Service - memory leak

  1. #1
    Join Date
    01.08.2018
    Posts
    1

    Default Service - memory leak

    Hello, 

    Our service reads some data from archive each minute (using Thread). But when this service is running, Runtime memory increases continuously.
    Could someone help me to detect, what is wrong with this part of code:


        public class ServiceExtension : IProjectServiceExtension
        {
            Thread t1;
            public void Start(IProject context, IBehavior behavior)
            {
                t1 = new Thread(() => Calculation(context));
                t1.Priority = ThreadPriority.Highest;
                t1.Start();
            }
            public void Calculation(IProject context)
            {
                IRuntimeArchive RuntimeArchive = null;
                IEnumerable<IRuntimeArchiveVariable> ArchiveVariables = null;
                IRuntimeArchiveVariable ArchiveVariable = null;

                while (true){
                    try{
                        //Gets necessary archive of the project                             
                        RuntimeArchive = (from X in context.RuntimeArchiveCollection where X.Name == "1MIN_1D" select X).First();

                        if (RuntimeArchive == null){
                            Debug.Print("No archive available!");
                            return;
                        }

                        //Gets variables
                        ArchiveVariables = (from X in RuntimeArchive.VariableCollection where X.Name.Contains(".ActivePower") && X.AggregationType.ToString().Contains("Average") select X);

                        foreach (var item in ArchiveVariables){
                            ArchiveVariable = null;

                            //Get variables
                            ArchiveVariable = (from X in RuntimeArchive.VariableCollection where X.Name != null && X.Name == "ActivePower" select X).FirstOrDefault();

                            //some logic
                            //........
                        }
                    }
                    catch (Exception e){
                        Debug.Print(e.ToString());
                    }

                    //Wait at least 1min
                    Thread.Sleep(60000);
                }
            }
        }


    Thanks!


  2. #2
    Join Date
    15.11.2016
    Posts
    84

    Default Re: Service - memory leak

    Hello,

    A common RAM leakage in Code with Archive-reading and writing is caused by the ArchiveFilters.

    ArchiveFilters are created and used.
    But those ArchiveFilters are never deleted.

    Is that the case here?

    BR,
    Georg

  3. #3
    Join Date
    24.05.2014
    Posts
    9

    Default AW: Service - memory leak

    You will never get out of the while loop?

    In my opinion your Code is not in a minute cycle.

Similar Threads

  1. archive memory leak.
    By backjahyun in forum VSTA
    Replies: 0
    Last Post: 30th May 2016, 10:30
  2. Zenon 7.11 as service
    By diemon in forum zenon Supervisor
    Replies: 5
    Last Post: 4th March 2015, 10:22
  3. Free memory (%) variable - for what kind of memory?
    By stolyarov_as in forum zenon Supervisor
    Replies: 4
    Last Post: 4th June 2013, 15:26
  4. Binding string variable to WPF, data leak?
    By sebastian.lenk in forum VSTA
    Replies: 1
    Last Post: 27th January 2013, 06:47
  5. Memory Leak when using IArchiveFilter.Query()
    By stolyarov_as in forum VSTA
    Replies: 7
    Last Post: 13th September 2011, 13:02

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •