Service - memory leak

Service - memory leak


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;
public void Calculation(IProject context)
IRuntimeArchive RuntimeArchive = null;
IEnumerable ArchiveVariables = null;
IRuntimeArchiveVariable ArchiveVariable = null;

while (true){
//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!");

//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){

//Wait at least 1min


This is a migrated post! Originally posted on 01.08.2018 by user igorrom. Please be aware that information can be outdated.