dimanche 19 avril 2015

How to stop a serious memory leak in livecode

I am attempting to build a simulated sonar waterfall display by deleting the bottom line of pixels of an image and appending a new line at the top to simulate the sonar display. This causes the LC memory to expand 3meg a second. Routine waterfall in card is:


on waterfall set lockScreen to true put "plot" into pImage


put 400 into pWidth put 200 into pHeight set the height of image pImage to pHeight set the width of image pImage to pWidth put the imageData of image pImage into iData


delete char -1600 to -1 of iData


put 1 into y put "" into nData repeat with x = 1 to pWidth



put random (10) into gry
put gry into r
put random (255) into g
put gry into b

put numToChar(255) into char ((y - 1) * pWidth * 4) + ((x - 1) * 4) + 1 of nData
put numToChar(r) into char ((y - 1) * pWidth * 4) + ((x - 1) * 4) + 2 of nData
put numToChar(g) into char ((y - 1) * pWidth * 4) + ((x - 1) * 4) + 3 of nData
put numToChar(b) into char ((y - 1) * pWidth * 4) + ((x - 1) * 4) + 4 of nData


end repeat put nData before iData set the imageData of image pImage to iData set the rect of image pImage to the rect of graphic "BlackBack" put "" into iData put "" into nData if the hilited of button "WaterFallon" is true then send waterFall to this card in .05 seconds


end waterFall


## a checkbox button starts the display with this code:

on mouseUp if the hilited of me is true then put "BlackBack" into pGraphic if there is a graphic pGraphic then delete graphic pGraphic create graphic pGraphic set the height of graphic pGraphic to 200 set the width of graphic pGraphic to 400 set the opaque of graphic pGraphic to true set the backgroundColor of graphic pGraphic to black set the topLeft of graphic pGraphic to 0,0 put "plot" into pImage if there is an image pImage then delete image pImage create image pImage send waterFall to this card end if end mouseUp


Aucun commentaire:

Enregistrer un commentaire