crashing from too many listeners?

My app has an odd behaviour, randomly after running a LONG time it will crash, the crash is like a freeze up where things stop responding. It doesn’t appear to be a bug in the software, but when it happens the background graphic that is full screen randomly goes pixelated. Could it be that having too many listeners is causing issues?

When you set an object to null, do the listeners that were on that object also get removed automatically? I’m creating dynamic objects and adding dynamic listeners to that object when they are created, so i am unsure how to remove those listeners from the object, since the listener I was passing in was created on the fly.

i.e.
object.addEventListener(“touch”, function() xxxxxx end);

If I do
object.parent:remove(object);
object=nil;

does the event listener stay in some table somewhere? Could this be why my app is crashing? any input appreciated, thanks! [import]uid: 6317 topic_id: 1133 reply_id: 301133[/import]

I don’t know the answer for Lua exactly, but I know in a language like ActionScript 3 that nulling an object and getting it garbage collected does NOT remove listeners tied to that object. Listeners must be specifically removed before you set the object to null.

I’m not sure how to do that with listeners that are created on the fly like that, but why not just use regular functions so you can remove the listeners with the function name? [import]uid: 6678 topic_id: 1133 reply_id: 2896[/import]

thanks, i’ve changed my code to take that into consideration. will see if it makes a difference. [import]uid: 6317 topic_id: 1133 reply_id: 2901[/import]

Before you remove the object, remove the listener out of the cue. [import]uid: 5712 topic_id: 1133 reply_id: 2904[/import]

@jwwtaker – yes, it sounds like it was leaking listeners, but did the revised approach help? [import]uid: 3007 topic_id: 1133 reply_id: 3016[/import]

no it did not. I am now explicitely removing all listeners, setting objects to nil, but still seeing my app crashing sporadically. [import]uid: 6317 topic_id: 1133 reply_id: 3046[/import]

At this point, I think we need the code to see what’s going on. Can you send that in and reference this thread? [import]uid: 3007 topic_id: 1133 reply_id: 3288[/import]