Applies To: |
|
Summary: |
It is important to understand when object
instances created using the CreateObject cicode function are
released.
If you do not manage when object instances are released, you may consume excessive amounts of memory and leave automation objects active when they are no longer required. |
Solution: |
If you assign an object created with the
function CreateObject to a local variable it remains in existence
until that variable goes out of scope. This means that such objects
are only released when the Cicode function in which you create them
ends.
If you assign such objects to module or global scope variables, then the object remains in existence until the variable is set to NullObject or another object is assigned to the same variable, provided the call to CreateObject is not made within a loop. It is recommended that you do not make calls to CreateObject within any form of loop such as WHILE or FOR loops. Objects created this way are only released when the Cicode function in which you create them ends regardless of the scope of the variable that they are assigned to. Using CreateObject in this way may result in system resources becoming exhausted. Avoid using code such as the following: /* In the following example, resources
associated with recursive calls to "MyObject" will never be
released as long as the function Forever continues to run. */ Instead you could use the following depending on the scope of the variable that you assign the object to: /* In the following example the variable
objTest is local. Resources associated with calls to "MyObject" are
released each time the function ProcessObject ends. */ |
Keywords: |
Related Links
Attachments