Announcement

Collapse
No announcement yet.

Garbage collection for PB?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Garbage collection for PB?

    For my xll (Excel addin) i would like to invent a new way to claim memory and destroy it right after the call.

    When Excel calls my function, i can not destroy the returned string.
    Using a STATIC is an option but not threadsafe.
    Using arrays holding memory pointers is an option, i am looking for something different so i tried this (not working):

    Code:
    [color=#0000FF]Class[/color] Class1
    
        [color=#0000FF]Class[/color] [color=#0000FF]Method[/color] [color=#0000FF]Destroy[/color]
            [color=#0000FF]MsgBox[/color] "END"
        [color=#0000FF]End[/color] [color=#0000FF]Method[/color]
    
        [color=#0000FF]Interface[/color] Interface1: [color=#0000FF]Inherit[/color] [color=#0000FF]IUnknown[/color]
            [color=#0000FF]Property[/color] [color=#0000FF]Get[/color] Value() [color=#0000FF]As[/color] [color=#0000FF]String[/color]
                [color=#0000FF]Property[/color] = "1234"
            [color=#0000FF]End[/color] [color=#0000FF]Property[/color]
        [color=#0000FF]End[/color] [color=#0000FF]Interface[/color]
    
    [color=#0000FF]End[/color] [color=#0000FF]Class[/color]
    
    [color=#0000FF]Function[/color] Test() [color=#0000FF]As[/color] [color=#0000FF]String[/color]
        [color=#0000FF]Local[/color] oInterface1 [color=#0000FF]As[/color] Interface1
        oInterface1 = [color=#0000FF]Class[/color] "Class1"
        [color=#0000FF]Function[/color] = oInterface1.Value()
    [color=#0000FF]End[/color] [color=#0000FF]Function[/color]
    
    [color=#007F00]' Execute[/color]
    [color=#0000FF]MsgBox[/color] Test()
    Unf. the msgbox END is executed before getting the "1234"

    Maybe you have an idea similar to this and handy to use?

    hellobasic

  • #2
    >Local oInterface1 As Interface1

    Per doc (hard to fnd), any LOCAL "as <interface>" variables are automatically cleaned up when exiting the function. (ie LET varname=NOTHING is done for you).

    What is it you want to explicitly destroy or not destroy? The string (property value)?
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Of course this example is wrong but i would like to destroy after the caller has obtained the data (Excel).

      You could use a timer enuming com interfaces and check a status flag for example.

      Looking for something clever with a similar approach.
      hellobasic

      Comment


      • #4
        Because the callee(your object) is returning a string, what is wrong with conforming to the
        rules of COM by having your object allocate the string using SysAllocString. The caller is
        responsible for freeing a string returned via an out parameter using SysFreeString.
        Dominic Mitchell
        Phoenix Visual Designer
        http://www.phnxthunder.com

        Comment


        • #5
          I know but there are exceptions, like Excel/xll
          Unless i am very wrong here.
          hellobasic

          Comment


          • #6
            Maybe you could/should ask in an MS-Excel user or developer group? Those folks would have to know about doing this kind of stuff specifically with MS-Excel.

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Yes, of course.
              hellobasic

              Comment

              Working...
              X