When working with the Fore language in Foresight Analytics Platform, garbage collection is implemented that helps delete unused objects and free computer memory. The garbage collector starts automatically at system idle time.
If other development environments are used to work with Fore language resources, the application developer must manage the allocation and release of memory. The following methods of the Prognoz.Platform.Interop.Fore.IForeRuntime interface start the collection process:
CollectFullGarbage. It starts cyclic memory clean that deletes all unused objects and the related objects that are no longer being used. The method is executed until its algorithm finds and deletes unused objects. (Method execution may take a considerable amount of time).
CollectGarbage. It performs a memory clean cycle. Returns True if some objects have been deleted. The Check output parameter is set to True if no errors occurred at the method runtime.
The methods starting garbage collection, which is executed in asynchronous mode in another thread, can be used:
RequestFullClean. It starts garbage collection providing a possibility to limit its execution time. If the specified time is not enough for checking and cleaning, the process will be aborted and it will be resumed when required conditions will be restored.
RequestPartitialClean. It performs a memory clean cycle.
These methods should be called within connection to the repository, with which the user is working.
An example of garbage collector start:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Prognoz.Platform.Interop.Fore;
using Prognoz.Platform.Interop.Metabase;
namespace TestProject
{
public partial class Form1 : Prognoz.Platform.Forms.Net.ForeNetFormVS
{
public Form1()
{
InitializeComponent();
}
//...
private void button1_Click(object sender, EventArgs e)
{
IForeServices Svc = (IForeServices)this.Metabase;
IForeRuntime ForeRun = Svc.GetRuntime();
ForeRun.CollectFullGarbage();
}
//...
}
}
public static void collectGarbage(IMetabase mb)
{
IForeServices svc = new IForeServices(mb);
IForeRuntime foreRun = svc.doGetRuntime();
foreRun.doCollectFullGarbage();
}
def collectGarbage():
import foresight.fore as fore
foreRun = fore.CForeRuntime.Create()
foreRun.CollectFullGarbage()
See also:
Using Foresight Analytics Platform Resources in Third-Party Applications