Visual Basic COM memory usage

2019-07-19 05:16发布

My question relates to the old technology. Yet it matters a lot to me to get a thorough answer. Could a Visual Basic expert answer me or include links to other sites and sheds light on this memory usage question please? I believe that I had not drafted my question clearly enough in my previous posting.

Consider the following VB 6 code in a custom COM plus object on a page on an e-commerce site:

Dim globalArray(30, 100000) 

'Assign long and short strings to the globalArray elements.
'Also some of the elements of globalArray hold smaller arrays. And also load the xml:

Set objGlobalDom = CreateObject("msxml2.FreeThreadedDomDocument.6.0") 
objGlobalDom.loadXML (xmlStr)
Application.lock
Set Application("objGlobalDom") = objGlobalDom
Application("globalArray")  = globalArray
Application.unlock

With any new session the following variable assignments are done:

set Session("objGlobalDom") =  Application("objGlobalDom")
session("globalArray") = Application("objGlobalDom")

Let's suppose that the Application("objGlobalDom") will contain an xml with some 1000 nodes and each node takes about 3k of memory. Let’s say the array will take some 50 meg of memory.

Considering VB6 and COM object:

  1. I understand that each instance of the object references the object’s data.
    What I don’t understand is:
    If session("objGlobalDom") does not contain a copy of the application("objGlobalDom"), why changes in the data of session("objGlobalDom") are not automatically reflected in the data of application("objGlobalDom")? Is the reference of session("objGlobalDom") to Apllication("globalDom") only for reading the data of Application("objGlobalDom")?

  2. According to Microsoft, in a situation such as my globalArray example, the session("globalArray") always gets a copy of the Application("globalArray") and so Microsoft discourages assigning the array to session variables. But it is not clear to me that in the case of COM object and object reference, does the assignment of set Session("objGlobalDom") = Application("objGlobalDom") copies the array to the session variable?

0条回答
登录 后发表回答