When a CORBA application returns a list of CORBA objects through IiopRequest calls, they are not automatically saved in memory for subsequent use. To support the calling of these CORBA objects, the generated script introduced IiopObjectByIor and IiopObjectCreate calls to create the CORBA objects from hardcoded values recorded in the script. This works fine if there is no change in the CORBA object IOR between recording and replay. However, in certain applications, the CORBA objects include session-related information in the IOR and consequently, the recorded IOR in the script cannot be used to reconstruct a valid CORBA object during replay.
 
To address this requirement, the returned list of CORBA objects can be stored in a list for subsequent use:
 
    IiopRequest(ghObjContainer, "get_objects");
    for nElem0 := 1 to IiopGetLong(ghObjContainer) do // length of Return = 8
      ghObjRef := 0; 
      IiopGetObject(ghObjContainer, ghObjRef); // Return_reference
      // save objects for later use
      ListAdd(gObjectList, ghObjRef);
      //IiopObjectRelease(ghObjRef); // do not release object at this point
 
In the example above, gObjectList is a BDL list type (list of number) that contains a list of CORBA object handles.
ListAdd will add the CORBA object handle in ghObjRef to the list, gObjectList.
 

·        Note that the variable used in the IiopGetObject call, ghObjRef, had to be initialized to 0 within the loop and before its use in the IiopGetObject call. This is because the parameter for storing the CORBA object handle in the IiopGetObject call is defined as inout. To explain further:

 
If the value of the variable ghObjRef is initially zero, a new unique number will be assigned to this variable to reference the returned CORBA object (from the IiopGetObject call).
 
If the value is non-zero, that same number will be used to reference the returned CORBA object and in doing so, the binding between the number and the initial assigned object will be lost.
 

·        When the CORBA objects in the list are no longer required, they can be released by looping through each element of the list and calling IiopObjectRelease for each CORBA object.

Calling ListClear does not release CORBA objects as it is not IIOP-aware. Following code illustrates the suggested technique:
 
    for nElem := 1 to ListGetLength(gObjectList) do
      ListGetAt(gObjectList, nElem, hObj);   
      IiopObjectRelease(hObj);
    end;
    ListClear(gObjectList); 
 
 

·        If more than one variable references a CORBA object, a single IiopObjectRelease call is sufficient to release that single CORBA object. There is no need to repeat the IiopObjectRelease for each variable that reference the CORBA object.