1Ci Support Help Center home page
Submit a request
Sign in
  1. 1Ci Support
  2. 1C:Enterprise Development Standards
  3. Client/server interaction

RAM usage optimization

  • Client/server interaction
    • Using modules with reusable return values
    • Using values affecting client application behavior
    • Getting predefined values on the client
    • Minimizing server calls number
    • Minimizing the code run on the client
    • Access to the file system from the configuration code
    • RAM usage optimization
    • Timeouts when using external resources

Scope: managed applications, mobile applications, and ordinary applications.

Best practices

1. When developing solutions, keep in mind possible RAM size.  Inefficient memory consumption can significantly slow down multi-user systems.

Avoid large data structures in RAM. If the business logic data size is not limited, restrict it by processing data by batches and saving results to the base or files.

2. If data size selected from the infobase is not limited, receive data from the infobase by batches of a fixed size.
Incorrect:

 Query = New Query;
 Query.Text =
  "SELECT
  | Products.Ref,
  | Products.Description,
  | Products.ProductKind
  |FROM
  | Catalog.Products AS Products";

 // Exporting the whole catalog into the value table
Products = Query.Execute().Export(); 
 For each ProductItem From Products Do
  // Processing a catalog item
  // ...
 EndDo;

The full query result is exported to the memory (the value table).
Also incorrect:

 Query = New Query;
 Query.Text =
  "SELECT
  | Products.Ref,
  | Products.Description,
  | Products.ProductKind
  |FROM
  | Catalog.Products AS Products";

 QueryResult = Query.Execute();
 // Query result iteration
DetailedRecordsSelection = QueryResult.Select();
 While DetailedRecordsSelection.Next() Do
  // Processing a selection item
  // ...
 EndDo;

Upon query execution, the full result is also exported to the memory first (*).

* Note. If a 32-bit platform version is used and the query result exceeds the existing memory size, data is first written to a hard drive and then read when calling Selection.Next().

It is correct to limit the query result artificially:

AllDataProcessed = False;
While True Do
 Query = New Query;
 Query.Text =
  "SELECT FIRST 1000
  | Products.Ref,
  | Products.Description,
  | Products.ProductKind
  |FROM
  | Catalog.Products AS Products
  |WHERE
  | <Condition of unprocessed records selection>";

 QueryResult = Query.Execute();
 AllDataProcessed = QueryResult.Blank();
 If AllDataProcessed Then
  Abort;
 EndIf;

 // Iterating through a query result batch
DetailedRecordsSelection = QueryResult.Select();
 While DetailedRecordsSelection.Next() Do
  // Processing a selection item
  // ...
 EndDo;

EndDo;

Also correct:

 Selection = Catalogs.Products.Select(..., Filter);
 While Selection.Next() Do
  // Processing a selection item
  // ...
 EndDo;

In this case, 1C:Enterprise receives data from the infobase by batches of a fixed size.

1C:Enterprise also limits the number of selection items in dynamic lists queries.

3. Do not handle large XML documents using 1C:Enterprise language objects designed to process whole files. For example, text documents in TextDocument, XML documents in DOMDocument, and HTML documents in HTMLDocument. Do not create XDTO packages the size of a full XML file in the memory.

Otherwise, a full file is loaded into RAM. An exception is made when random access to a file is required, for example, to its particular part.

Use the following objects for sequential writing and reading: XMLReader, TextReader, XMLWriter, and TextWriter. With these objects, you can read files in batches and consume memory efficiently.

When using XTDO mechanisms, it is incorrect to export a full XML file to the memory (XTDOFactory.ReadXML(XMLReader)). Instead, read an XML file in batches using the XMLReader object and deserialize its separate parts (tags) using the XDTO factory.

4. Another common reason for inefficient memory consumption is memory leaks. Memory leaks occur because of circular references as memory is allocated but not freed. For example, if there are objects with other objects inside that refer to the top object. As a result, a circular reference is created.
A simplified circular reference:

Data = New Structure;
Data.Insert("Key", Data);

We recommend that you remove (clear) references when an object is no longer needed.
For the example mentioned above:

Data.Key = Undefined;

To detect memory leaks, you can use the technological log and include <leaks> in its settings file logcfg.xml.

For more information, see

  • 1C:Enterprise Developer Guide, Appendix 3. Description and location of internal files - logcfg.xml
  • Searching for circular references

5. Excessive use of common modules with reusable return values can also increase memory consumption. 

© 2020-2021 1C INTERNATIONAL LLC www.1Ci.com Support policy