Player instances aren't being GC'd in a weak table

I’m not sure if this is a bug, nevertheless I don’t have access to bug reports.

local players = {}
setmetatable(players, {__mode = "kv"})

game.Players.PlayerAdded:Connect(function(p)
    players[p] = true
end)

while true do
    for k, v in pairs(players) do print(k, v) end
    wait(5)
end

Am I missing something? It’s a player ofc it’s not gonna get garbage collected lol.

This is how you can access bug reports as New Member.

yes once i leave the reference to the player still exists

i guess the new member role is completely pointless then

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

This should help explain your issue for the instances (players in your case) but why would you want weak values?

1 Like

The issue is that it isn’t being gc’d.

If it were GC’d the object may be unintentionally destroyed

Again, the problem is that it isn’t being gc’d when there’s no longer a reference to the player.

And I just gave you a reason why that isn’t a problem.

The problem is that the instance still isn’t being gc’d when it no longer exists, thus a memory leak. If you can’t understand that then you should probably stop replying to threads you don’t know jack about.

1 Like

It’s a player. It’ll get gc’d once the player leaves don’t worry lol.

Sidenote: pls respect your peers

5 Likes

THE PROBLEM IS IT ISN’T GETTING GC’D ONCE THE PLAYER LEAVES, hopefully you can read that :).

:heart: respect bro

5 Likes

@Acreol gave you the straightforward most answer. Read that post he quoted.

If you’ve read the post you’ll know that the solution to the problem is literally the exact opposite of what’s happening here. It’s saying how instances are gc’d in a weak table, however that’s not happening here, if you bothered to read any of my past replies you’d understand that (:smile::wink::heart:).

This is better suited in bug reports honestly.

Can someone post this on bug reports instead of trying to prove me wrong without any idea of what’s going on here?

@TaaRt already posted a quote answering that question too lol.

Respectfully, can someone who knows what they’re talking about respond or post this in bug reports please?

1 Like

That’s
Not
The
Process

If anything you’re worsening your chances with every post