Search for data in all lua registries of allowed script level environment

I am currently debugging my [server-side part of my] game to search for a memory leak related to the player object persisting after the player leaves
The problem is that the player object persisting not only causes a memory leak, but also actually breaks my game because I make some assumptions that if the player object exists, its data will eventually load (thus yielding the game)

(I use weak instance tables)

--[[
	WIT: Weak Instance Table
	
	Lets weak tables use instances as weak references
	https://devforum.roblox.com/t/weak-tables-dont-work-with-instances/86634
	
	It doesn't really know when it is destroyed/gced though bc that is impossible, instead it knows if Parent is nil :/
		
--]]

local refs={}
local function add(ins)
	refs[ins]=true
end
local function rem(ins)
	refs[ins]=nil
end
for _,ins in next,game:GetDescendants()do
	pcall(add,ins)
end
game.DescendantAdded:connect(function(ins)
	pcall(add,ins)
end)
game.DescendantRemoving:connect(function(ins)
	pcall(rem,ins)
end)

return nil

Searching would always be for debugging reasons so I don’t think speed would really matter
It would suffice for me if the relevant modules/functions were returned, but stack trace would be 11/10

If this is too complicated, it would be nice if it at least existed for players&characters since their creation and deletion is universal throughout all Roblox games

What? I’m confused by the contents of this request. What are you actually asking for? There’s a format to follow for feature requests that involve a user story. Can you follow that?

1 Like

I am not sure how I can make the post clearer without turning it into a lecture

if you want the template, here it is:

As a Roblox developer, it is currently impossible to see where data is being stored throughout all of your scripts without interpreting your lua code yourself

If Roblox is able to address my issue, it would improve my game and my development experience because it would speed up my debugging and would greatly aid me in patching memory leaks to keep the game playable over long periods

The specific issue that motivated me to write this post (my user story) is listed in the OP:

I’m closing this thread as it’s not clear:

  1. What the problem is
  2. How this actually effects any developers

What you’re doing is already horribly unconventional, you’re storing a reference to every single instance in the data model. If you’re concerned with memory leaks, then that’s certainly not the way to go about solving them.

I can’t think of any prior art that actually does this. I don’t see why this is Roblox’s issue.

2 Likes