Consultor Eletrônico



Kbase P102822: Performance: RELEASE OBJECT slow after calling an MS Word Application Object Quit() method.
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   04/04/2005
Status: Unverified

SYMPTOM(s):

Performance: RELEASE OBJECT slow after calling an MS Word Application Object Quit() method.

Using the 4GL PAUSE(1) appears to make the RELEASE OBJECT statement execute faster most of the time.

The following code executes in ~150 seconds WITH the PAUSE(1) statement and executes in ~125 seconds WITHOUT the PAUSE(1) statement.
DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE iStartTime AS INTEGER NO-UNDO.
DEFINE VARIABLE iEndTime AS INTEGER NO-UNDO.
DEFINE VARIABLE iTimeElapse AS INTEGER NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE hWordApplication AS COM-HANDLE .
define variable hWordDocument AS COM-HANDLE.

cFileName = "test.doc".
ETIME(TRUE).
iStartTime = 0.
DO iCounter = 1 TO 100:
CREATE 'Word.Application':U hWordApplication.
hWordApplication:VISIBLE = FALSE.
hWordDocument = hWordApplication:Documents:OPEN(cFileName, FALSE, FALSE, FALSE, '':U, '':U, false, '':U, '':U, 0).
hWordDocument:Activate.
hWordApplication:ActiveDocument:Save().
hWordApplication:ActiveDocument:Close().
RELEASE OBJECT hWordDocument.
hWordApplication:Quit().
PAUSE(1) NO-MESSAGE.
RELEASE OBJECT hWordApplication.
END.
iEndTime = ETIME.
iTimeElapse = iEndTime - iStartTime.
MESSAGE STRING(iTimeElapse)
VIEW-AS ALERT-BOX INFO BUTTONS OK.

CAUSE:

Word does not follow the regular COM rules when it comes to shutting down. The Quit() method runs asynchronously and terminates the Word process. The regular COM rule is that as long as anyone has an outstanding reference to the object, it is supposed to stay alive. So until we do the RELEASE, the Word process should stay around. However, Word does not follow this rule. So by the time we get to the RELEASE, the Word process may or may not already be gone. It is at this very point of the process that the performance of the RELEASE statement is dramatically degraded.

FIX:

Since the Quit() method actually terminates the Word Application Object, do not use either the PAUSE(1) or the RELEASE OBJECT statements. This produces impressive performance results. The attached code sample executes in ~75 seconds (compared to ~150 seconds) when both the RELEASE and the PAUSE(1) statements are commented out.
Although dropping the RELEASE statement may result in a small memory leak within the Progress process. Fortunately, it is very small, so if this code does not occur very often, it should not affect anything.