Weak Tables don't work with Instances

There would be a non-negligible performance overhead.

Yes, but there is what most likely is an even larger overhead by keeping track of instances under DataModel by either DescendantAdded/Removed or other connections.

Is this fix really so complicated and performance-damaging to add? From my perspective, it just seems like adding a special case for collecting instances (checking if parent ~= nil).

Unfortunately yes. The key thing to recognize is that when you write: print(game.a.b.c.d) you’re allocating 4 different object references, and doing the additional tracking to hold permanent references while stuff is in the DataModel would have to happen on every single one of those.

You also add a bunch of memory pressure, because as soon as you’ve gotten an object reference, to ensure reference stability, that reference would have to be held until the object gets removed from the DataModel, vs right now it can be collected right away if you didn’t end up explicitly holding onto it.

1 Like

I guess this is best kept in its current state then. Any ideas for alternatives that don’t require connections or caching instances in a messy way? At the moment it seems like the only ways to fix this issue have performance issues (either in the engine with C or by the user with Lua).

Depends what exactly it is you’re trying to accomplish got a specific problem to solve?

1 Like

Every time a character is added a model (‘Appearance’, filled with custom clothing) is added to it and I am adding that model to an ignore list used by raycasting so that rays do not collide with the clothing parts. The ignore list is a weak table so I don’t have to worry about connections or checking if the characters have been removed.

Edit: Just remembered the CanQuery property now exists so I’ll probably switch to that, but this was my original use case.

1 Like