Skip to main content
July 4, 2011
Question

Dynamically generated UI Elements make Air hang

  • July 4, 2011
  • 1 reply
  • 507 views

Hi there everyone!

This is question that most probably come from my limited knowledge of the Adobe Flex framework and its functioning but so far I was unable to retrieve the required information all by myself.

So the problem is: I have an Adobe AIR desktop application (SDK 4.1 / 4.5) that generates UI Elements dynamically and adds them to the main stage surface by the <applicationInstance>.addElement(<UIElement>);. Once not required anymore, I just remove them from the stage interface by the  <applicationInstance>.removeElement(<UIElement>);. the UI elements are generated by a Timer. back.

The application hangs and stops responding after a while. the faster I generate the elements, the sooner it hangs. There are no more than 25 elements displayed on the stage in the same time. Nonetheless the application freezes by throwing an exception to Adobe Flash Builder that would eventually close the application and say it terminated unexpectedly.

My guess is that somehow the Elements are not completely removed by the removeElement, or the addElement method keeps on feeding the stack even though some indexes are already freed. Each UIElement loads a quite big resource eating some RAM as well, but I checked the memory usage of the application and it is steady with no  memory leak, so the Elements seem to be removed and the memory is given back in fact.

Could anyone help me please what is the proper method to implement this kind of behaviour or let me know if I'm looking for the cause of this problem at the wrong place and the problem comes probably from somewhere else?

This topic has been closed for replies.

1 reply

chris.campbell
Legend
July 11, 2011

I haven't seen this one before.  A couple of things:  Does this also occur if you're doing this in a web app (removing AIR from the equation?)  If you're encountering a crash and can reliably reproduce the issue, please open a bug report at bugbase.adobe.com and include sample code that illustrates the issue.  Finally, since this sounds like it might be flex related, I'd also recommend posting about it over on the Flex forums to see if anyone there has seen this occur before.

Thanks,

Chris

July 25, 2011

Hi. Sorry for the misleading question. In fact I was able to come up with the solution to my own problem. I happened to have a timer instanciated in each object that included a GUI element. Unfortunately I did not stop the timers in the destructors. It turns out that Flex framework garbage collector does not destroy the timers if they are not stopped. Hence the GUI elements get destroyed and freed up but there are more and more timers running in the background. By the time I had about a thousand of them the framerate began decreasing rapidly due to the fact that Flash is single threaded. Finally the whole application just hung.

I just realized my mistake while rewriting the code to the factory method pattern. Thanks for the help and your response anyways. But at least now this problem has a mark on the Internet. If someone experiences the same maybe s/he will find the answer here.