2

I've set up In-App Billing v3 on an app according to the Google Developers page on that subject. I'm pretty much following the same approach and steps from their TrivialDrive sample application (as can be seen, for example, here).

It all works OK (querying inventory, purchases, item consumption, etc. work) but I've been facing some rather annoying memory leaks.

If I switch the phone's orientation a couple of times, cause Garbage Collection, do a HPROF dump and analyse using MAT, I can see that a bunch of Threads are still alive and kicking, while they shouldn't.

Android IabHelper causing Memory Leak?

It's not a lot of memory, but it still accumulates in any Activity where I use IabHelper... And yes, I am disposing my IabHelper instance (hell, even set the listeners as null...) in my Activity's onDestroy():

@Override
protected void onDestroy() {
     super.onDestroy();

     (...)

     if (mHelper != null) 
        mHelper.dispose();

     mHelper = null;
     mGotInventoryListener = null;
     mPurchaseFinishedListener = null;
 }

Is anyone having the same issues? Can anyone point me in the right direction to fix this? Thanks in advance for any input.

user1987392
  • 3,921
  • 4
  • 34
  • 59

1 Answers1

2

After banging my head against the wall, fruitlessly looking at my code over and over again and doing some more research I've found this question:

Thread objects not garbage collected after being finished

Apparently, the fact that these Threads aren't collected by the Garbage Collector is not related to a memory leak but instead to the fact that I'm running the app in debug mode. Upon running the app in run mode (still in Eclipse), Thread garbage collection takes place.

Furthermore:

"The debugger and garbage collector are currently loosely integrated. The VM guarantees that any object the debugger is aware of is not garbage collected until after the debugger disconnects. This can result in a buildup of objects over time while the debugger is connected. For example, if the debugger sees a running thread, the associated Thread object is not garbage collected even after the thread terminates."

(bottom of: http://developer.android.com/tools/debugging/index.html, as noted by @ptoinson)

Community
  • 1
  • 1
user1987392
  • 3,921
  • 4
  • 34
  • 59