Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

part not getting properly GC'ed? help please?

Asked by
Myune 24
5 years ago
Edited 5 years ago

i am trying to make a part spawn in the workspace when a player is added in a folder named "PartsInWorkspace". my issue is, when the player leaves i dont think it deletes from the game and gets GC'ed.

my first issue is my game has ungodly amount of untracked data, about 500mb in a blank, new baseplate, and on a good day like 300mb, which makes my overall memory 700 and sometimes 450 to 600. i feel my only way is to work around it. otherwise i dont really know how i can do this game idea at all because when my player moves the data goes up and doesnt ever come back down, especially when i stop testing and reenter it, the memory jumps up about 10-50mb. when i test the game with Player1 etc, it drops to about 500mb maybe 450, but it rises over time and doesnt stop(this is in a blank baseplate with nothing, and usually happens when the player moves).

so i am testing the ability to work around it and i created this script (the original works fine, this is an example script of what im working with.) i am afraid it isnt getting GC'ed when the player leaves the game, because i still notice memory rising, it does drop but less than a single mb, and it rises faster than it drops. also, lua GC is usually at 0% which tells me nothing is really getting cleaned up.

i read about scope also, but it wasnt too clear. is this "out of scope"?

one more thing, i read about disconnecting events, but when i do it doesnt activate for other players so, i assume that cant be done with this. i read about "return" as well but i dont know what that does, or how to use it in this case very well.

Thanks, any help is appreciated the code is below:

--/ all of this is located in  a ServerScript
--/ im gonna use a part for example to prevent a wall of code
--/can player added still reference the player?
game.Players.PlayerAdded:Connect(function(player)
    if player then
        local parts = game.ServerStorage.parts:GetChildren()
        for i=1,#parts do
            local v = parts[i]:Clone()
            if v.PartInfo.Value == player:WaitForChild("leaderstats").part.Value then
                v.Name = player.Name
                v.Parent = game.Workspace.PartsInWorkspace
                for i,bc in pairs(v:GetChildren())do
                    if (bc:IsA("BasePart")) then
                        bc.BrickColor = BrickColor.new("Alder")
                    end
                end
            end
        end
    end
end)

-- when i remove the part i do this:
game.Players.PlayerRemoving:Connect(function(player)
    for i,p in pairs(game.Workspace.PartsInWorkspace:GetChildren())do
        if (p:IsA("BasePart")) then
            if p.Name == player.Name then
                p:Destroy()
            end
        end
    end
end)
0
You really need to indent and format your code properly BlueTaslem 18071 — 5y
0
i updated it, does it look better now? o: Myune 24 — 5y
0
Please do not use GC, it confused me up until I read the script to find GetChildren. Also, how are you getting memory values (through Studio, Developer Console[F9 screen] on live server, task manager)? M39a9am3R 3210 — 5y
0
Don’t use get children? What alternative should I use? I meant garbage collect, but I am getting memory through F9 in the developer console, I don’t feel like this is getting cleaned up when the player leaves, I have bad memory issues on a blank baseplate Myune 24 — 5y

Answer this question