【问题标题】:Google Play Services LeakGoogle Play 服务泄露
【发布时间】:2014-03-08 22:23:04
【问题描述】:

我不久前开始使用 Google Play 游戏服务,昨天在检查 logcat 时我忍不住注意到了这个错误:

E/DataBuffer(3183):DataBuffer 对象内的内部数据泄漏 检测到!确保在所有 DataBuffer 上显式调用 close() 完成后扩展对象。 (内部对象: com.google.android.gms.common.data.DataHolder@40555410)

它连续出现多次。我不确定它为什么会出现。它不会让我的应用崩溃,也不会让谷歌成就/排行榜功能停止工作。

我只知道它与“unlockAchievementImmediate”和“submitScoreImmediate”函数有关。

有没有人遇到过这个问题或者有什么建议?


编辑:在我的应用中,我只使用“unlockAchievementImmediate”和“submitScoreImmediate”。这些函数不返回任何需要关闭的缓冲区。

【问题讨论】:

  • 当我使用 AppStateClient 的 onStateLoadedListener 时也会发生这种情况(这很有趣,因为甚至没有返回 Buffer 对象,所以不确定 Google 希望我如何关闭它!)

标签: android memory-leaks google-play-services google-play-games


【解决方案1】:

这些项目扩展了 DataBuffer:AchievementBuffer、AppStateBuffer、FilteredDataBuffer、GameBuffer、InvitationBuffer、LeaderboardBuffer、LeaderboardScoreBuffer、MetadataBuffer、MomentBuffer、ParticipantBuffer、PersonBuffer、PlayerBuffer、TurnBasedMatchBuffer。

这些通常可以在您的那些特定项目的听众中找到。例如:

public void onTurnBasedMatchesLoaded(int statusCode, LoadMatchesResponse response) 
{
    TurnBasedMatchBuffer buff = response.getMyTurnMatches();
    // do some stuff with buff
    buff.close()
}

public void onPlayersLoaded(int statusCode, PlayerBuffer buff) 
{
    Player p = buff.get(0);
    buff.close();
}

直到我退出我的应用程序并重新进入后才会报告该错误。如果我调用我的比赛 3 次并退出应用程序而不调用 buff.close(),我可以期望在再次打开它时看到 3 次警告。添加 buff.close() 并且它们消失。瞧!

【讨论】:

  • 虽然上述内容仍然正确,但我仍然发现我在某个地方有一个流氓,我无法用任何未关闭的缓冲区来解释......似乎只需登录、退出和重新打开就可以了足以导致这个。也许是我们正在实施的 jar 导致它。
  • Multiplayer/TurnBasedMatches 函数可能就是这种情况,但在我的应用程序中,我只使用“unlockAchievementImmediate”和“submitScoreImmediate”,它们不返回任何缓冲区。
【解决方案2】:

数据缓冲区的任何子类都需要被释放。因此,在您完成该对象后释放它。

Data Buffer 对象包含一个release() 方法,因此在您完成该对象后,只需使用databuffer.release(); 释放它即可。

【讨论】:

  • 在我开发应用程序时(我不知道从那以后是否有任何变化),我只使用了“unlockAchievementImmediate”和“submitScoreImmediate”方法。这些函数没有返回任何缓冲区,因此没有任何可以释放的东西。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-06
  • 2017-11-13
相关资源
最近更新 更多