I have a question about some behind-the-scenes Titanium architecture. A common UI element in many of my apps is the tableView. I use tableViews a lot, and some of them get very long (hundreds of custom rows with many child objects and event listeners).
I was wondering what the best practice is for clearing out a table?
I have seen:
table.setData(); table.setData(); table.data = ;They all appear to behave similarly. Are they equivalent? Is there a method better than any of these three?
My biggest concern is with the release of event listeners. When I work with the DOM I love using jQuery. In the past I used
element.html("") to empty out containers I wanted to reuse, until I learned that doing so does not release the event listeners and other jQuery data related with the child elements of the container. This results in a huge memory leak, so now I use
Do methods like
table.setData() release all of rows, their children, and their event listeners from memory? Or does it just overwrite the appearance of the table?
The tableView objects are a pivotal component of all the apps I make with Titanium, and I want to be sure I'm using them correctly. Cheers.
A few things to keep in mind... if each row only needs to accept one click aka the row... it is better to set the event listener to the table the each row. Also, the methods you posted would work just fine. It is worth noting however, that if you are not planing on reusing the table for a while it is probably better to null the table object and create a new one when needed... but thats a case by case thing. Also worth noting is when setting new data to a table, you do not need to set an empty value first, you can just set the new data...
Hope all that helps :)
Think you can help? Login to answer this question!