0
Not a bug

maximum number of event listeners?

r riksma 9 years ago in iRidium Script / Interface scripts updated by Ekaterina (head of support) 8 years ago 12
while adding a new feature to my project i ran into the following error message:

07-28-2015 12:10:31 Kernel.Info 192.168.253.102 [28-07-2015 12:10:31.000] WARNING Script exception: RangeError: /var/mobile/Containers/Data/Application/52D7C331-9EEE-43AB-9979-20E9A2C44C3D/Library/Caches/iRidiumMobile/project/Isyglt.js:96: error

The line defines an listener like this:
IR.AddListener(IR.EVENT_RECEIVE_TEXT,driver,function(text){});

if i try to create a listener elsewhere in the project some other listener that has worked fine before will give this error.
if i remove a random listener the error disappears.
It seems to me there is a maximum number of event listeners and i have reached this maximum.
Is this true, and is there any way to fix this?
Under review
You can create 1024 listeners in iRidium. Please send your UI to support email if you will not be able to solve this problem yourself
That's ok. I just didn't know there was a limit so i had some no-op functions in there that i can remove easily and with some work i might be able to combine some others.

Could you try and work out something in a future version to make sure we don't run into problems with this?
I can imagine there will be much larger projects than the one i'm working on.
These are my suggestions:
  • make it possible to remove listeners
  • let us reference created listeners (like items) so the current functions can be read and amended.
  • even better, make it possible to remove complete pages including all of its elements and listeners. This could also help with memory usage and other limits.
1. It is possible to remove listeners
2. you can add the counter of created listeners, like listener++ in each function started by listener. It is not a problem
function pressed () 
{
    IR.Log("action");
}
 
// add listener
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), pressed); 
 
// remove listener
IR.RemoveListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem("Item 61"), pressed);
3. You can do it with
IR.DeleteItem("Page 1");
I can imagine there will be much larger projects than the one i'm working on.
You have to optimize you scripts using prototypes and deleting of unused listeners
Great!
I thought removing listeners and pages wasn't possible yet, but if it is the limit of 1024 should be more than enough.
Thank you!
One amendment: IR.DeleteItem() works with Popups and Items, but not with Pages. But I hope it should be enough
Removing pages with all items on them would be a nice feature, but this should indeed be enough.
Just to confirm, a listener is automatically removed when you delete the item, correct?
I tested this with the following code but i would like to know for sure i'm not accidentally leaving stuff in memory:

function press (){IR.Log("abc");}

for( var i = 0; i > 5000; i++){
IR.GetItem("Page 1").CreateItem(IR.ITEM_BUTTON,'Button',10,10,200,100);
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem('Button'), press);
IR.DeleteItem(IR.GetItem("Page 1").GetItem('Button'));
}

IR.GetItem("Page 1").CreateItem(IR.ITEM_BUTTON,'Button',10,10,200,100);
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetItem("Page 1").GetItem('Button'), press);
Hi!

Listeners did not removed after delete the item, you need to remove listeners before deleting the item
ok, then i will have to do that.

is there any way to remove all listeners from an item or can i remove a listener by referencing it from a variable?
The only way i currently know how to remove a listener is not really straightforward because i will have to add a RemoveListener line every time i use AddListener so it's easy to make mistakes.

I have hit this limit with a large project where I need to change states based on project tokens as there is no feedbac.

The project is due to be handed over tomorrow.... aaagggghhhhh!!!!!


I have reduced as much as I can but there is a listener on each button, slider and edit and colour picker, and no way around this.


Suggestions anyone??? Please

Please create the listeners only on visible pages and remove them when hide the page