Friday, 2 May 2014

A fundamental part of PodTrapper is its ability to refresh your podcasts on the schedule you set. This way they're always available when you want them, much like iTunes would do on your PC if you left it open (except without the syncing). That means PodTrapper needs to be running *all the time* on your phone. Fortunately this is fully supported on BlackBerry. Unfortunately this brings with it all of the aspects you need to deal with when writing long running apps -- memory leaks (yes, even with java), resource limitations, thread based events, etc. For example, some of the earlier versions of PodTrapper (ok, maybe not so 'earlier') would parse feed xml and store data from the xml inside an episode object with String.substring(). I completely forgot that the JVM implements substring as a pointer to the location in the original string. So, if I had a 100k RSS feed, and I pulled out a 100 byte string with substring and stored it, the 100k RSS feed could never be freed. (This isn't exactly what happened, but it's close enough and much simpler to explain). Making matters worse is the limited memory available on early BlackBerry devices. My curve has 32MB of RAM and 64MB of flash. The flash can be used for paging if it's available, but on my device only about 20MB of it is, and that fills up fast installing applications (PodTrapper alone is 350k). Realizing that the OS and other apps also have to fit in RAM, leaking a 100kb string becomes a huge problem. There are lots of forum posts by people trying to figure out why their phone keeps running out of memory and needs to be rebooted. It's a large enough problem that there are apps for automatically restarting your phone. I can definitely see why Apple has been hesitant to open up background processing on the iPhone. It's really easy for bad developers to make the whole platform look bad.

No comments:

Post a Comment