Need insight on crash and debug output for this.patcher.remove()


    Trevor being Trevor
    May 24 2023 | 5:32 pm
    I have a max patch that dynamically creates and removes a ton of objects via the this.patcher.newdefault() and this.patcher.remove() methods to essentially build and destroy a dynamic UI via Javascript as needed. The objects are stored in global arrays by type (for example, all the textedit objects) so the functions that create and destroy the UI both have access to them.
    It's been relatively smooth. However, as I have continued to build using the same methodology I encounter an odd crash now and then. After troubleshooting, the problem comes down to the use of a this.patcher.remove() in specific instances. Literally, if I comment it out the line(s), the crash does not occur.
    If anybody with more knowledge on Max debug output could give any insight into following info I think I could get to the bottom of it. I am happy to provide more info if needed, just wanted to avoid writing a novel of a post. These are snippets of the Max debug output when running a bunch of this.patcher.remove() methods. I am wondering if the bolded lines are potential issues that are compounding into a crash later.
    Looks Normal:
    object_unregister: slating unique sym u857004814 for reuse
    unregistering: u562004824 in 00000000000B1890. ref count now 0
    Should I be concerned?
    unregistering: u597005447 in 00000000000B1890. ref count now 0
    object_unregister: slating unique sym u597005447 for reuse
    object_detach: object 000000002D0E4170 wasn't attached to object 0000000029D6F890 
    unregistering: u915005449 in 000000000014C738. ref count now 0
    object_unregister: slating unique sym u915005449 for reuse
    unregistering: u587005469 in 00000000000B1890. ref count now 0
    Another snippet after adding in some lines that makes it crash in certain instances.
    registering: u184003150 in 00000000009267B8
    registering: u363003151 in 00000000009267B8
    unregistering: u512002235 in 00000000009267B8. ref count now 0
    object_unregister: slating unique sym u512002235 for reuse
    warning: object 0000000027D28780 was freed but was still attached to 1 registered object(s) 
    registering: u176003152 in 00000000008DC8A0
    Lastly, here's the Max Crash Summary
    Lastly, here's the Max Crash Summary

    • Trevor being Trevor's icon
      Trevor being Trevor
      Jul 26 2023 | 5:03 pm
      Following up on this post, I ended up doing a full rewrite to address various growing pains and this issue resolved thankfully. However, two things I wish I would of known...
      1. gc() - appears to call JavaScript garbage collection, there isn't much documentation on this function specifically, but seems to be a known technique on the forum. I call it after the user does full removal of all the dynamically created objects.
      2. In a different thread a user recently posted that there is a way to print the stack trace using:
      var err = new Error(); 
      post(err.stack + "\n");