XojoScript destruction

  1. 3 months ago

    Arthur v

    Feb 15 Netherlands

    Hi again!

    I have a thread with a XojoScript object running fine. The problem is I'm having trouble getting rid of the script object afterwards.

    It appears that I have to clear all properties in the object manually, where I was hoping I could simply do a myXojoScript.Reset and myXojoScript = Nil for example.

    This approach does not return the memory taken by the object though. I also tried to kill the whole thread object that runs the script, but although that does finish (?), the memory problem stays.

    Am I missing something here or do I indeed have to clear all properties of myXojoScript before it destructs and frees the memory?

  2. Arthur C

    Feb 15 Pre-Release Testers, Xojo Pro Whitinsville, MA

    Is it possible that there are other objects in the program that have references to the XojoScript Object? That can prevent the destruction of the Object and the recovery of the memory. Apologies in advance if you have already checked for this scenario.

  3. Arthur v

    Feb 15 Netherlands

    No prob, thanks for your input! :)

    But yeah, I've already double-checked that. Only the thread that runs the script object has a reference...

  4. Michel B

    Feb 15 Pre-Release Testers, Xojo Pro
    Edited 3 months ago by Michel B

    How are you creating the XojoScript instance ?

  5. Arthur v

    Feb 15 Netherlands

    In the run event of the thread I do:

    atScript = New AirTableScript

    Which is a property of the thread and a type from super XojoScript in the app.

    Is that what you mean?

  6. Michel B

    Feb 15 Pre-Release Testers, Xojo Pro
    Edited 3 months ago by Michel B

    Since XojoScript does not have a close method, I suspect it cannot be destroyed that easily.

    Threads do not have a close method that would remove them either.

    I would try instead of attaching atScript to a module or to the window, to attach it to a new window (if necessary invisible) or a containerControl. Or even dragged on that CC or window. Then when necessary closing the CC or window should destroy whatever is on it, and with some luck the XojoScript as well.

    Hey, you might as well put the thread there as well.

  7. Arthur v

    Feb 15 Netherlands

    Since I don't have a GUI, it would be a module. Never used that before though. I'll see if I can build a prototype...

  8. Michel B

    Feb 15 Pre-Release Testers, Xojo Pro
    Edited 3 months ago by Michel B

    You cannot destroy a module. It is not an instance.

  9. Arthur v

    Feb 15 Netherlands

    Ah. I see. I also can't have my events it seems. Makes sense from a GUI point of view though.

  10. Arthur v

    Feb 16 Netherlands

    Found it. In the Constructor of the XojoScript object I initialized a couple of local properties that never got Nilled again.

    Totally forgot I ever used that mechanism...

    Still strange IMHO that the thread object that hosts the script object can destruct with some of the script object still in memory. Or am I misunderstanding something?

  11. Michel B

    Feb 16 Pre-Release Testers, Xojo Pro

    I am not sure killing the thread really destructs it. More probably, it simply stops it.

  12. Arthur v

    Feb 16 Netherlands

    Well, the Destructor method fired for the thread, but initially not for the script inside that object.

    I can trust the Destructor as a signal that I cleaned up nicely, right?

  13. Michel B

    Feb 16 Pre-Release Testers, Xojo Pro

    Normally, yes.

  14. Arthur v

    Feb 16 Netherlands

    Sounds like another Feedback then.

    But first some sleep. ;)

  15. Will S

    Feb 16 Santa Cruz 

    What are these properties you have to nil for the script to destruct? It sounds like there could be a circular reference somewhere and this breaks that.

  16. Michel B

    Feb 17 Pre-Release Testers, Xojo Pro

    Have you tried to put a destructor on the XojoScript ? That could give you additional information.

  17. Arthur v

    Feb 17 Netherlands

    With some fresh eyes it turned out to be the ultimate circular reference indeed. In the constructor I did:

    Self.context = Self

    Which I had to clear from the outside after finishing the script for the XojoScript object to destroy.

    I used a destructor on both the thread and the script object. That's how I found out that the thread ended fine but the script object inside it did not.

    I'm still not sure if that's normal behavior. I figured for the thread object to destruct, the included xojoscript would have to be gone too... Is this a bug?

    @Michel B: did you mean additional information besides it not destructing?

  18. Michel B

    Feb 17 Pre-Release Testers, Xojo Pro

    You found the reason for the bug. Indeed, I think it is normal that the thread won't destruct with something alive in there. What is of concern, is that it might create another bug when the method ends, as it will stay there hanging around.

    There is such a bug report in Desktop where if a thread was still running when the window closed, it crashed the entire program.

  19. Arthur v

    Feb 17 Netherlands

    Feedback #47035

    Cheers all. :)

or Sign Up to reply!