gpt4 book ai didi

java - 使用 IabHelper 时内存泄漏(应用内结算 v3)

转载 作者:行者123 更新时间:2023-11-30 09:02:23 24 4
gpt4 key购买 nike

我已经根据 Google Developers page on that subject 在应用程序上设置了应用内结算 v3 .我几乎遵循了他们的 TrivialDrive 示例应用程序中的相同方法和步骤(例如,可以看到 here )。

一切正常(查询库存、购买、元素消耗等工作),但我一直面临一些相当烦人的内存泄漏。

如果我多次切换手机的方向,导致垃圾收集,执行 HPROF 转储并使用 MAT 进行分析,我可以看到一堆 Threads 还活着,但它们不应该。

Android IabHelper causing Memory Leak?

它不是很多内存,但它仍然在我使用 IabHelper 的任何 Activity 中累积......是的,我正在处理我的 IabHelper 我 Activity 的 onDestroy() 中的实例(见鬼,甚至将监听器设置为 null...):

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

(...)

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

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

有人遇到同样的问题吗?谁能指出我正确的方向来解决这个问题?在此先感谢您的任何输入。

最佳答案

在用头撞墙后,一遍又一遍地毫无结果地查看我的代码并进行更多研究后,我发现了这个问题:

Thread objects not garbage collected after being finished

显然,这些线程未被垃圾收集器收集的事实与内存泄漏无关,而是与我在 debug 模式下运行应用程序这一事实有关。在 run 模式下运行应用程序(仍在 Eclipse 中),线程垃圾收集发生。

此外:

"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)

关于java - 使用 IabHelper 时内存泄漏(应用内结算 v3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25982442/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com