Skip to main content

Swizzling

Swizzling

If you open (load into memory) an instance of a persistent object, and use an object that it references, then this referenced object is automatically opened. This process is referred to as swizzling; it is also sometimes known as “lazy loading.”

For example, the following code opens an instance of Sample.EmployeeOpens in a new tab object and automatically swizzles (opens) its related Sample.CompanyOpens in a new tab object by referring to it using dot syntax:

 // Open employee "101"
 Set emp = ##class(Sample.Employee).%OpenId(101)

 // Automatically open Sample.Company by referring to it:
 Write "Company: ",emp.Company.Name,!

When an object is swizzled, it is opened using the default concurrency value of the class it is a member of, not the concurrency value of the object that swizzles it. See “Object Concurrency Options,” later in this chapter.

A swizzled object is removed from memory as soon as no objects or variables refer to it.

FeedbackOpens in a new tab