Creating a video inside a gridview creates a memory leak

It looks like creating a new video inside a gridview:drawCell method never frees memory from the video. This eventually fills up the entire memory until the simulator or the device crashes. Here’s a video demonstrating the effect.

Here’s an extract from the corresponding code:

function gridview:drawCell(section, row, column, selected, x, y, width, height)

	local ctx =, height,

		local video =
		video = nil
	ctx:draw(x, y)


Attached is a minimum example to reproduce this bug. (3.0 MB)

Tested with SDK 1.12.2, in the Simulator and on device.

I also mentioned this in the #developer channel in Discord.

Found it! I hadn't noticed before because I was only ever creating a single video player. If we'd provided a way to load a new file into a video player you could keep a single player around and reuse it for each file you want to preview, but that doesn't exist yet. The best workaround I can think of is caching the preview images so that you're only leaking one video player per file instead of one every redraw.

Pushing a fix to the queue now!

I did exactly what you suggested to fix this, works great! And good idea for providing a way to load other videos (the same way audio players work), that'd be useful indeed! Thank you!

1 Like