Memory Leak, with Tables

Hi, I have posted this in the general questions area, but im not sure if that was the right place…

I have some code that allows the user to draw lines on the screen on touch, once finished i have a restartscene which is another scene entirely, when the scene which yo draw in restarts its using about 30kb more memory.

Ive isoltaed it to the draw function (ie, if no lines are drawn then the level restarts fine)

Can anyone see anything that might cause an issue in this code? LevelLayer and all vars are pre declared, and levellayer is inserted into the main group… this function is on a runtime touch event…

Im DESPERATE!!

[lua]

–function that draws the line on the screen---------------------

local draw_line = function(e)

        

        

      if e.phase == “began” then

          currx = e.x;

          curry = e.y;

        prev_x = currx

        prev_y = curry

    

      elseif e.phase == “moved” then

          currx = e.x;

          curry = e.y;    

    

      --first check that we are allowed to draw

      if(drawMode == true)then

    

      --next only draw above ground level

            if(curry < contHeight)and(curry > 0)then

            

                if(currx > 0)and(currx < contWidth)then

    

                    if(UsedInk < TotalInk)then

                        

                        linesA[line_number] = display.newLine(prev_x, prev_y, currx, curry) 

                        linesA[line_number]:setColor(255, 255, 255, 255)

                        linesA[line_number].width = 1

                        linesA[line_number].name = “plasma”;

                        

                        linesB[line_number] = display.newLine(prev_x, prev_y, currx, curry) 

                        linesB[line_number]:setColor(255, 117, 254, 253)

                        linesB[line_number].width = 3

                        

                        linesC[line_number] = display.newLine(prev_x, prev_y, currx, curry) 

                        linesC[line_number]:setColor(255, 60, 255, 255)

                        linesC[line_number].width = 5

                        

                        linesD[line_number] = display.newLine(prev_x, prev_y, currx, curry) 

                        linesD[line_number]:setColor(255, 20, 247, 255)

                        linesD[line_number].width = 7    

                        

                        linesE[line_number] = display.newLine(prev_x, prev_y, currx, curry) 

                        linesE[line_number]:setColor(255, 20, 247, 160)

                        linesE[line_number].width = 9    

                        

                        linesF[line_number] = display.newLine(prev_x, prev_y, currx, curry) 

                        linesF[line_number]:setColor(255, 20, 247, 90)

                        linesF[line_number].width = 11

                        

                        linesG[line_number] = display.newLine(prev_x, prev_y, currx, curry) 

                        linesG[line_number]:setColor(255, 20, 247, 10)

                        linesG[line_number].width = 13;

                        

                        LevelLayer:insert(linesG[line_number]);

                        LevelLayer:insert(linesF[line_number]);

                        LevelLayer:insert(linesE[line_number]);

                        LevelLayer:insert(linesD[line_number]);

                        LevelLayer:insert(linesC[line_number]);

                        LevelLayer:insert(linesB[line_number]);

                        LevelLayer:insert(linesA[line_number]);

                        local dist_x = e.x - prev_x

                        local dist_y = e.y - prev_y

                        

                        --Add a physics body that’s a flat polygon that follows each segment of the line

                        physics.addBody(linesA[line_number], “static”, { density = 0.8, friction = 0.4, bounce = 0.1, shape = {0, 0, dist_x, dist_y, 0, 0} } )

                        

                        prev_x = currx;

                        prev_y = curry;

                        line_number = line_number + 1

                        UsedInk = UsedInk + 1;

                    end

                    

                end

                

            end

        end

        

      elseif e.phase == “ended” then

          --resetAll();

      end

    

end

[/lua]