Storing values in object and form module variables

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 the 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 the creation of circular 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 the deletion of the objects in a regular way.

It is impossible to name all situations 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.

Next page: User interruption of module execution

Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.