Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Can cyclic reference cause memory leaks? - Gideros Forum

Can cyclic reference cause memory leaks?

ar2rsawseenar2rsawseen Maintainer
edited January 2012 in General questions
Hello all,

I was looking for a solution, to handle multiple animations (multiple movie clips) for one object, based on different object states (collision, landing, etc). And ended up using cyclic reference, here is a very simple example:
--for example we have couple of movie clips with animations
local crying = MovieClip.new{...}
local smiling = MovieClip.new{...}
local hit = MovieClip.new{...}
--storing references in one lua table
local animations = {}
animations.crying = crying
animations.smiling = smiling
animations.hit = hit
--and to get other animations from current animation
--storing lua table reference in other animations
crying.other = animations
smiling.other = animations
hit.other = animations
As you see animations references crying and crying references animations, which again references crying, etc.

Of course it is not the only solution, I could reference to global array with animations etc, but still out of curiosity,
is it safe to use something like that? Can it cause memory leaks?

I guess it depends on implementation of garbage collector, and so far testing app didn't notice any significant memory usage outburst.


Sign In or Register to comment.