How to destroy an instance?


I’m creating instances of a sub-symbol, adding them to a group, and animating them each time the user touches the screen. After the animation is complete, that sub-symbol is no longer needed.

If I simply remove the sub-symbol from the group once the animation is complete, is that sufficient for it to be garbage collected, or do I need to destroy the instance somehow?

I’m trying to be smart about resource utilization, so I’m wondering what the best practice is for this type of thing.


There’s actually not currently a mechanism to destroy things; it’s a bit complicated as everything on the Javascript side has a native counterpart, and Javascript doesn’t provide any hooks for when things get garbage collected so there’s no way of hooking into garbage collection to free up stuff on the native side (which is where most of the memory is used).

In general we’d use a pool of things - so if you can re-use a previous instance of the symbol rather than creating a new one that’s probably better. Basic nodes don’t actually use much memory though so you shouldn’t need to worry about them too much. If you are able to re-use instances you can remove it from your scene and stick it somewhere else (like temporary array in a script node let inactiveInstances = []; or something) then it won’t have any performance implications for rendering.


Great idea. Thanks for the reply!