Microsoft KB Archive/247319

= PRB: PUBLIC Variables Not Released from InProcess Servers in ASP =

Article ID: 247319

Article Last Modified on 12/11/1999

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q247319



SYMPTOMS
Public variables declared in an in-process Microsoft Visual FoxPro OLE Automation Server, launched from an ASP page, are not released when the OLE Automation Server is released.



CAUSE
PUBLIC variables declared within an in-process OLE Automation Server are public to the thread and any object on the thread. PUBLIC variables are not released until the thread has been uninitialized and the client has unloaded the in-process server. Setting the instance of the in-process server object to "nothing" does not unload the server.



RESOLUTION
Set the scope of variables used within in-process OLE Automation Servers, used with Active Server Pages, to PRIVATE rather than PUBLIC.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a new project named MTHREAD.  Add a new program file to the project, using the following code: DEFINE CLASS mthread AS CUSTOM OLEPUBLIC

FUNCTION PublicHit LPARAMETER lnSecs LOCAL x     lnSecs=IIF(EMPTY(lnSecs),0,lnSecs)

IF lnSecs > 60 lnSecs = 61 ENDIF

IF VARTYPE(gnPubValue) = "N" gnPubValue = gnPubValue + 1 ELSE PUBLIC gnPubValue gnPubValue = 1 ENDIF

IF VARTYPE(gnPrivValue) = "N" gnPrivValue = gnPrivValue + 1 ELSE PRIVATE gnPrivValue gnPrivValue = 1 ENDIF

DECLARE Sleep IN WIN32API INTEGER FOR x=1 TO lnSecs FOR x=1 TO lnSecs Sleep(1000) ENDFOR ENDFOR

DECLARE INTEGER GetCurrentThreadId IN WIN32API lcHTML = [ ] + CHR(13) + ; [ ] + ; "The request completed in " + TRANS(lnSecs) + " seconds." + [ ] +CHR(13) +; [ ] + CHR(13) + ; "The current Thread ID is: " + TRANS(GetCurrentThreadId) + " "+CHR(13) + ; "The Public Value (gnPubValue) : = " + TRANS(gnPubValue) + " "+ CHR(13) + ; "The Private Value (gnPrivValue): = " + TRANS(gnPrivValue) + " "

RETURN lcHTML ENDFUNC ENDDEFINE  Click the Build button on the Project Manager, and select either a Single-threaded COM server (dll) or a Multi-threaded COM server (dll). Install the COM Server and run-time files on a computer running Internet Information Server. Register the COM Server.</li>  Create an Active Server Page named TEST.ASP in the IIS WWWROOT directory using the following code, and make certain that the directory has execute privileges: <%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY>

<% Set oVFPApp = Server.CreateObject("mthread.mthread")

Response.Write oVFPApp.PublicHit

set oVFPApp = nothing

%>

</BODY> </HTML> </li> Launch your Web Browser and navigate to the Active Server Page that was created in step 4. Refresh the page several times, and note that the value of gnPubValue is incremented each time the page is refreshed.</li> Close your Web Browser.</li> Launch your Web Browser and navigate to the Active Server Page that was created in step 4. Note that the value of gnPubValue is not 1.</li></ol>

<div class="references_section">