The 1C:Enterprise platform implements the object lifetime management strategy based on reference counting. Each platform object has a reference counter. If a new reference to an object is created (the object is assigned to a variable), the counter is incremented by 1. If a reference is deleted, the counter is decremented by 1. Once the reference counter value becomes 0, the object is deleted and the memory allocated for the object is released.
This strategy allows creation of circular references. A circular reference appears when objects reference each other. This leads to a situation when each of the objects that form a circular reference cannot be deleted. This, in turn, leads to memory leaks.
Avoid creation of curcular references whenever possible. Following simple rules during configuration development helps you avoid problems related to circular references. If a circular reference is created, define a moment for breaking it to ensure deletion of the objects in a regular way.
It is impossible to name all sutuations that lead to circular references. Here are some examples:
- Storing a reference to an object (or form, or record set) in an object (form, record set) variable leads to a circular reference; the object (form, record set) will never be deleted.
- Storing a reference to a parent object in a child object together with storing a reference to a child object in a parent object leads to a situation when both objects will never be deleted.
Note that, in addition to references created by module variables, references to objects can be created when objects are passed to script methods. For example, adding a value list to itself (as one of the values) leads to a circular reference.