My QBCore vehicle manager is gradually increasing memory usage by 2-3MB every 30 minutes during peak times. The spawn/delete cycle seems to leave orphaned entities that don't get properly cleaned up, especially when players disconnect. Here's the basic spawn function I'm using:
function spawnVehicle(model, coords)
local ped = GetPlayerPed(source)
local veh = CreateVehicleServerSetter(GetHashKey(model), coords.x, coords.y, coords.z, coords.w)
local netId = NetworkGetNetworkIdFromEntity(veh)
-- Store entity handle in global table
VehicleManager[netId] = { entity = veh, owner = source }
-- No validation of entity creation success
return netId
end
-- Deletion doesn't validate if entity still exists
function deleteVehicle(netId)
local veh = VehicleManager[netId].entity
DeleteEntity(veh) -- May fail if entity already cleaned up by OneSync
VehicleManager[netId] = nil
endSometimes getting 'Entity reference invalid' warnings during cleanup and old vehicles persist in different routing buckets after disconnection.
NoobMaster · 02/09/2026
Sign in to reply.