Jahn, Ray (R.) wrote:

Thanks to the explanation by Andrew Douglas Pitonyak and Mathias Bauer.

Scope: global vs. local vs. any other
Are all objects returned by CreateUnoService() global objects and therefore not to be disposed of by users? If the answer is dependent on the exact service requested, is there a documentation specifying which are global and which are other types? I tried the Developers Guide, version 2.0, and a few OO mail lists. Not much luck so far.


One might argue that the situation is worse than you thought, because it is not just CreateUnoService that can return a global object :-)
I looked in the Developer's Guide regarding a Database Context and I found the following:


From the API perspective, these functions are mirrored in the com.sun.star.sdb.DatabaseContext service. The database context is a container for data sources. It is a singleton, that is, it may exist only once in a running OpenOffice.org API instance and can be accessed by creating it at the global service manager of the office.

In case you missed it, it says that the object is a singleton. This means that there is only one. The correct way to dispose of this object is probably to call dispose(). Of course, there is only one so if you do choose to call dispose(), then there will not be any instances of this object. You will rarely use the dispose method. If you obtain a connection, you should close() the connection. The only time that you are likely to use dispose would be for "content". For example, you might choose to dispose of some text content that is inserted in a document to make it go away. I usually use a different method to specifically remove the text content, however.

FunctionAccess:
Is the FunctionAccess service object returned by CreateUnoService() a pointer to a singleton object, that is, the actual singleton FunctionAccess service object?


What options do you have to remove FunctionAccess? If you do not see a way to return or close it, then it is probably a global object :-) Lets test and see...

Sub CheckObjects
 Dim obj1
 Dim obj2
 obj1 = CreateUnoService("com.sun.star.sheet.FunctionAccess")
 obj2 = CreateUnoService("com.sun.star.sheet.FunctionAccess")
 If EqualUnoObjects(obj1, obj2) Then
   Print "The objects are the same"
 Else
   Print "The objects are NOT the same"
 End If
End Sub

The same object is returned each time, so probably yes. The Developer's Guide has an example and the object is NOT removed afterwards, so there is probably only one...

Memory management (leakage):
Is the memory automatically reclaimed (at an unspecified time) when the service objects go out of scope?
Is the memory management guideline independent of the script languages (Basic, Java-BeanShell, etc.)


For the singleton objects, they will not be released until OOo is closed. The point at which the memory used to reference to the object is released will be dependent on the language that you use and when garbage collection occurs. This is probably more clearly defined in C++ than in say Java, which can pretty much garbage collect when it wants to.
I have no idea what happens to a text table that is created but never inserted into a document or an instance of a user defined data type that is dynamically created.


There is no concern for memory leakage if all service objects returned by 
CreateUnoService() are mere pointers (handles) to the real (global) service 
objects.

Efficiency:
The overhead of CreateUnoService() becomes noticeable when the repetition approaches 100000 - 1000000 (1 million) in Basic on MS Windows 2000.


As does the call to the routine that performs the work.

Regards,


' --- example code in OO Basic 1.9.95 option explicit

' simulate repetitive calls from sheet cells to CreateUnoService()
' assume 10 - 20 calls to built-in sheet functions to satisfy one cell request
' assume the same number of calls to CreateUnoService() due to the partition of algorithm logic Sub test_01()
dim ii as long, cnt as long, err as long
cnt = 1000000
for ii = 0 to cnt step 1
err = call_sheet_functions()
next
msgbox( "call_sheet_functions() repeats " & cnt )
End Sub



function call_sheet_functions() as long Dim oFunction as variant oFunction = CreateUnoService("com.sun.star.sheet.FunctionAccess")

' data processing section, call sheet built-in functions

call_sheet_functions = 0
end function

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-- Andrew Pitonyak My Macro Document: http://www.pitonyak.org/AndrewMacro.sxw My Macro Book: http://www.hentzenwerke.com/catalog/oome.htm Free Info: http://www.pitonyak.org/oo.php


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to