Ejecta icon indicating copy to clipboard operation
Ejecta copied to clipboard

Question: Releasing native Image resources

Open apitaru opened this issue 14 years ago • 2 comments

I'd love to get your thinking on how I can free up native Image resources once the JavaScript image objets are garbage-collected. It'll allow developers to load (and release) multiple SpriteSheets without crashing the device on a memory warning.

I hope I'm not missing something obvious.

Thanks, Amit

apitaru avatar Nov 06 '12 23:11 apitaru

Ejecta should already free textures, once the Image objects are released by the GC.

You can also set an Image's src to an empty string if you don't want to wait for the GC. This will release the EJTexture object used by the Image:

img.src = '';

phoboslab avatar Nov 06 '12 23:11 phoboslab

Oh that's wonderful.

For some reason it wasn't getting reset when GC picked up the img object (I'll post details if I can figure it out), however it works like a charm when I set img.src manually as you suggested.

Thank you!

PS - apologies for the duplicate issues, a silly mistake.

apitaru avatar Nov 07 '12 02:11 apitaru