HTC Thunderbolt = ShopSavvy Crashes!

http://www.minihelicopter.net/AH64Apache/AH-64%20Apache.jpg

UPDATE 2: Okay, I’ve got another update. First, there are some of you who haven’t seen the app crash on your Thunderbolt (we have no idea how this could be the case), but for most of you (like us) ShopSavvy crashes hard almost immediately. Our lead Android developer explains what is going on in this cut and paste job:

After much toying, tweaking, and hacking I can safely say that the problem we are encountering with the HTC Thunderbolt can not be fixed from our side of the fence.  Doing testing across the Nexus S, Nexus One, Evo, and Thunderbolt I have pinned the problem down to the garbage collection mechanisms on the Thunderbolt; both on the native heap and in the dalvik.  On each product screen we place a large image of the product on the lower half of the screen.  Each time we create this image an allocation is done on the native heap to hold the actual Bitmap bytes while a small reference object is placed on the dalvik. The error that currently causes ShopSavvy to crash involves the native heap growing until the operating system can no longer allocate anymore space causing the program to crash from the native side of the application, not the dalvik.

In order to free memory on the native heap an Android programmer can either ensure that 1. The bitmap reference on the dalvik is garbage collected which will in turn call the native destructor which will delete the buffer on the native heap or 2. Call the recycle() method on the dalvik Bitmap object which will immediately delete the buffer on the native heap.  By calling delete on the native buffer the operating system should then mark that buffer space as reusable and the next allocation should be able to take advantage of the space ensuring that the native heap does not need to grow in size.  Therefore, to track down the problem I needed to ensure that both methods were used to keep the native heap under control.

The first round of tests involved ensuring that the Bitmap.recycle() method was called on each product image to ensure that the bitmap should then be immediately recycled.  I included a Bitmap.recycle() and a logging statement on activity shutdown methods as well as in the activity finalizer to ensure that the method was called and the bitmap destroyed.  On the Thunderbolt calling recycle() on the bitmap never caused an increase in free native heap space.  Therefore every time the product screen was visited another 1-2mb would be allocated onto the native heap until the program would get an OOM (Out Of Memory error).  If we compare memory consumption of the Evo with the Thunderbolt; after viewing 6 product screens, the native memory usage on the Thunderbolt would grow from 6Mb to 24Mb, where the Evo would grow from 9.9Mb to 14Mb (where it stayed).

The next round of tests determined the activity of the Dalvik garbage collection mechanisms.  I went through the code and put printouts in the finalize methods of our product screen objects. This ensures that I get a message every time the dalvik deleted one of these objects from memory. I also wrapped our BitmapDrawables to ensure that the finalize method was being called on them as well.  On the Nexus S, Nexus One, and Evo the garbage collector would kick in fairly quickly; after about 4 product screen views.  I received messages that the activities, tasks, drawables, and tasks associated with the product screen were all purged from memory.  This was also confirmed by my native heap gaining free space and not growing in overall size.  The thunderbolt however never called the finalize methods on anything other than Tasks.  This means that every activity was still being kept in memory along with WebViews and BitmapDrawables. Even though the references to all objects were deleted on the activity shutdown methods; the objects were never cleared from memory causing large memory usage.

I’m unable to recommend any fixes at this time.  All Android best practices are being exercised in our app.  We have concluded that all references are being deleted and all bitmaps have been recycled either by manually calling recycle or through the Bitmap object being finalized.

UPDATE: The bug is NOT network IO related, but bitmap related. Thunderbolt’s version of Android is allocating WAY too much memory when we are trying to create a bitmap. We are still stumped. What if we delivered a TIFF instead? Maybe a PNG? Just kidding – working on it now.

If you are a proud owner of the HTC Thunderbolt you will note that MANY Android apps seem to be crashing. ShopSavvy will crash almost immediately. We know why it is crashing, but we aren’t sure how to fix it. Here is a lay person’s explanation of what is going on:

When trying to create an image that should be 3k the system is allocating a 16mb buffer to load the bitmap. As you can see below the bitmap size is 16mb when it should be like 3k.

E/AndroidRuntime(11212): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=8239KB, Allocated=6688KB, Bitmap Size=16371KB)

Andy Rifken points out that HTC seems to have modified the Apache HTTP client libraries. His issue is with the default socket buffer for HttpParameters API, but we think that if he is right and they did modify Apache on the device it may be the cause of the problem we are facing. There is a work around Apache that we are currently working on – if it works look for an update shortly. If not, we will be forced to wait on a response from HTC.


5 Responses

  1. valerie says:

    I’ve had mine since the day after launch and have had no crashing issues at all. Everything including shopsavvy runs very smooth.

  2. SandyinMiami says:

    I’ve been using Savvy on my TB with no problems at all up until yesterday. All of a sudden it just started crashing constantly. I will look forward to an update….hopefully soon.

    • Thanks for the update. Anyone who uses ShopSavvy for more than a few scans will see the crash. It is a problem with the Thunderbolt’s garbage collection – a memory problem with the phone. HTC is aware of the problem and we have been assured a fix is coming in the next few weeks. Google confirmed it is an HTC issue and let us know there wasn’t any sort of fancy work around we could do on our side.

  3. Shane says:

    Hi Alex, thanks for sharing this. Had me scratching my head over this for some time now.

    Anyway, is there an update from HTC regarding a fix? I’m still encountering crashes on my app.

    Thanks.

Leave a Reply