Skip to main content

Destroy an image object (:destroy)

Declaration

img:destroy()

Description

Immediately release memory of the image object. The destroyed image cannot be used again
Performance tip: if you frequently create new images, call this to avoid high memory usage that may freeze/crash the device
If not creating images frequently, you may omit; no memory leak. Lua GC will reclaim later

Example

sys.alert("Click OK, start monitoring screen in 1s")
sys.msleep(1000)
local img = screen.image()
while 1 do
local scn = screen.image()
local x, y, s = scn:cv_find_image(img)
scn:destroy()
if s < 95 then break end
sys.msleep(10)
end
sys.alert("Screen changed")

Note: This example uses functions outside this chapter sys.alert, sys.msleep