Severe Memory Leak Problems

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ThatOneGuy
Posts: 77
Joined: Fri Jan 04, 2013 9:57 am

Severe Memory Leak Problems

Post by ThatOneGuy » Sun Jul 26, 2015 12:57 am

I have been playing around with images and files in LiveCode and have noticed some extremely severe memory leaks.

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Severe Memory Leak Problems

Post by FourthWorld » Sun Jul 26, 2015 1:12 am

Confirmed here on Ubuntu 14.04 with LC 7.1dp1.

Please submit this to the bug queue so they can address it
http://quality.runrev.com/

Leaks tend to get a very high priority there, so with any luck they may be able to fix this before dp2.

Thanks -
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

ThatOneGuy
Posts: 77
Joined: Fri Jan 04, 2013 9:57 am

Re: Severe Memory Leak Problems

Post by ThatOneGuy » Sun Jul 26, 2015 8:51 am


FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Severe Memory Leak Problems

Post by FourthWorld » Mon Jul 27, 2015 2:52 pm

Thanks for submitting that - its status is "In Progress" already, so it looks like this will be resolved shortly.

Memory leaks and crashers are rare in LiveCode, because those tend to get high priority once a good recipe is submitted for it. Thanks for taking the time to post that good recipe.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Severe Memory Leak Problems

Post by mwieder » Tue Jul 28, 2015 12:51 am

Yeah, I reported similar leaks in libpango in 15617 and attached a valgrind dump. Peter reproduced the leaks there as well, so I'm hopeful that a fix is on the way.
And it looks like a simple change https://github.com/runrev/livecode/pull/2572/files.

Post Reply