• Manual
  • HAPI Namespace
Show / Hide Table of Contents
  • General Information
  • Object-Oriented Specification
  • Memory Management
  • Error Handling
  • Using the Hugin C#/.NET Core API
  • Examples
    • Example 1: Load and Propagate
    • Example 2: Build and Propagate
    • Example 3: Sequential Learning
    • Example 4: Node naming scheme for OOBNs
  • Acknowledgements

Memory Management

The Hugin C#/.NET Core API is comprised of two parts: a managed part written in C#, and an unmanaged part written in C. Contrary to managed objects, unmanaged data objects are not automatically reclaimed (or garbage collected) when a program stops referring to them. Therefore, some explicit memory management is needed in order to avoid memory leaks.

For example, when a managed Domain object is no longer needed, it should be deleted. Deleting a Domain object will cause all the unmanaged objects associated with the Domain object to be implicitly deleted: the unmanaged domain object, the unmanaged node objects, etc. At the same time all managed objects corresponding to those unmanaged objects are marked "dead" (that is, invoking methods on such objects will cause ExceptionObjectNotAlive exceptions). When the managed program stops referring to dead objects, the garbage collector can reclaim them.

Only objects that are not "owned by" other objects require explicit deletion. (For example, nodes are owned by a Domain or a Class object, a Class object is owned by a ClassCollection object, etc.) An object owned by another object is automatically deleted when its owner is deleted.

The following objects are not owned by other objects and must therefore be explicitly deleted in the managed code:

  • Domain objects
  • ClassCollection objects
  • DataSet objects
  • Table objects created by the GetMarginal(NodeList) method of the Domain class
  • Table objects created by the GetDistribution() method of the ContinuousChanceNode class
In this article
Back to top Copyright (C) 2019-2025 Hugin Expert A/S