Request: Posting Topic in Scripting Support

What is the best way to “connect” two parts without causing a memory leak?

I am trying to make a fire propagation system which spreads fire from one part to nearby parts. Right now, the system is set up in an OOP manner. Here is some psuedocode that shows how my system is set up:

local parts = {}
local partInfo = { ["FireSize"] = 0, ["ConnectedParts"] = {}}

parts[game.Workspace.Part] = copyTable(partInfo)

After looping through every part and setting up the partInfo table, I use Workspace:FindPartsInRegion3 for each part to find nearby parts and add them to the ConnectedParts table. However, after reading stravant’s article about memory leaks, I am worried that I am causing a memory leak. Here is the section that worries me.

do -- OOPS!... still leaking, it doesn't have to be a direct reference!
    local p ='Part')
    local dataTable = {Message = "Test"; Part = p}
    p.Touched:connect(function() print(dataTable.message) end)

Am I causing a memory leak? If so, what is the best way to store nearby parts for each part? I am aware that I could use Workspace:FindPartsInRegion3 each time I need to reference nearby parts, but it is much faster to run that only once.

1 Like

This topic was automatically closed after 1 minute. New replies are no longer allowed.