It seems as though LiveCode likes to create new versions of variables when changing scope and then quickly lose the pointers to the previous versions, making them impossible to delete or free up in any way, even after returning to the previous scope.
One attempt to edit images by changing the imagedata of the image stored in a secondary buffer causes about 300 MB of memory leakage on each test run or about 1 MB per edit of the secondary buffer. This constitutes an exact duplicate of the secondary buffer being made and the previous version being subsequently lost in memory every time a function is called to edit it.
Placing the code below in the stack script of a stack with a 640x400 image named "image" will cause the aforementioned memory leak when running "test".
Code: Select all
local imgWidth
local imgHeight
local pixelData
local theWriteBuffer
on setupImage
put the width of img "image" into imgHeight
put the height of img "image" into imgWidth
put the imagedata of img "image" into theWriteBuffer
end setupImage
on test
setupImage
setDrawColor(255, 255, 0, 0)
repeat with x = 1 to 100
drawPixel( x,100)
end repeat
setDrawColor(255, 0, 255, 0)
repeat with x = 1 to 100
drawPixel( x,110)
end repeat
setDrawColor(255, 0, 0, 255)
repeat with x = 1 to 100
drawPixel( x,120)
end repeat
writeBuffer
end test
on setDrawColor colorData
put numtochar(item 4 of colorData) & numtochar(item 3 of colorData) & numtochar(item 2 of colorData) & numtochar(item 1 of colorData) into pixelData
end setDrawColor
on drawPixel theLoc
local thePixel
put (item 1 of theLoc * 4) + ((item 2 of theLoc) * imgWidth * 4) into thePixel
put pixelData into char thePixel to (thePixel + 3) of theWriteBuffer
end drawPixel
on writeBuffer
set the imagedata of img "image" to theWriteBuffer
end writeBuffer