I have a program which basically downloads a database from the server at the launch, parses the JSON, and stores it in the memory (it has a few hundred items), then I attach a function to the Location event, filter the location change to 30 m (don't call the following except the moving delta is bigger thant 30 m), then filter this array by the distance of the objects. Of course I have to calculate all distances every time to be able to filter the array and I also have to sort is to be able to display the correct list of values on the screen.
The values are displayed the following way: 1. I initialize a new array, 2. go through the filtered items with for, 3. create a tableviewrow for each filtered item (with my creator function, which sets a few labels on them), 4. push the row into the array created in (1), 5. then set the tableview's content with this array (with the setData()).
This results an incredible lag on the real device (iPhone 4) and some small lag on the Simulator. What do I mean lag? If you click something in an other window of the app, like a button, it opens the corresponding window or does the corresponding function in 15-30 secs. With Instruments I was able to determine that the main reason of this lag is that filtering the datas and refilling the tables uses 100% CPU and multiple requests overlap eachother. To be more specific, Titanium's Garbage Collector uses the most CPU cycles, almost the 95% of the time.
How do I supposed to update a table if not this way? Is it maybe anything other than this wrong? What do you think?
If you prefer, I can post code quotes and a video demonstrating the lag.