i have tried to make a map reloading system (it deleted the map from workspace and copies the map from server storage)
the thing is, this isn’t even code related, but after deleting the map from explorer itself MEMORY DOES NOT GO DOWN!!!
it’s not really as code related BUT I REALLY NEED HELP WITH THIS. If you die too many times your game will just crash because the memory does not go down after the map gets deleted.
before:
local number = 0
task.wait()
local assetnumber = workspace.Values.AssetNumber.Value - 300
local function loaded()
game:GetService("ContentProvider"):PreloadAsync({workspace.Pizzeria})
script.Parent.Text = "Loading lighting"
task.wait(10)
warn("loaded")
workspace.CurrentCamera.CFrame = workspace.Pizzeria.Cam.OfficeCamera1.CFrame
script.Parent.Parent.Visible = false
script:Clone().Enabled = false
for _, songs in pairs(workspace.MenuRelatedInstances:GetDescendants()) do
if songs:IsA("Sound") then
songs:Stop()
end
end
game.ReplicatedStorage.StartScriptsRemote:FireServer()
script:Clone()
script:Destroy()
end
local number = 0
local connection
local function loading()
task.delay(25, loaded)
script.Parent.Parent.Visible = true
script.Parent.Parent.Parent.Parent.Menu.Enabled = false
connection = workspace:WaitForChild("Pizzeria").DescendantAdded:Connect(function()
number += 1
warn(assetnumber, number)
script.Parent.Text = "Reloading map. This may take a while."
if number >= assetnumber then
loaded()
connection:Disconnect()
end
end)
end
script.Parent.Parent.Parent.Parent.Menu["New Game"].MouseButton1Click:Connect(loading)
yeah, it’s not really well written but it deletes itself which frees up memory which can actually be seen but the map still takes a lot of memory and frees up like 200 mb out of way more
One potential propblem is in line 11: script:Clone(). You clone it twice (Line 11, Line 18) and only remove once. Every time you call the function, you keep 1 more of the scripts.
Do you have custom data structures (tables with data in them) in your application? If so, show what are you adding, and what happens if you call a custom ‘destroy’ method for the object.
The easiest way to delete maps and remove them from memory is to use Debris as shown in the following script:
local Debris = game:GetService('Debris') -- Get the Debris Service
local Map -- Define your map object
local RemovalTime = 0 -- Add an optional delay before removing the map
Debris:AddItem(Map,RemovalTime) -- Add an item to the Debris queue for deletion