Memory leaks 如何阻止严重的内存泄漏

Memory leaks 如何阻止严重的内存泄漏,memory-leaks,livecode,Memory Leaks,Livecode,我试图通过删除图像像素的底线并在顶部添加一条新线来模拟声纳显示,从而构建一个模拟声纳瀑布显示。这导致LC内存每秒扩展3毫克。卡片中的常规瀑布是: 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

我试图通过删除图像像素的底线并在顶部添加一条新线来模拟声纳显示,从而构建一个模拟声纳瀑布显示。这导致LC内存每秒扩展3毫克。卡片中的常规瀑布是:

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

在重复循环的末尾,即
结束重复之前添加以下行:

wait 0 millisecs with messages
这给了LiveCode一点时间来更新GUI并丢弃旧版本的屏幕