Back
アプリでボタンを押すたびに、LogCat でこの例外を受け取ります。
アクティビティは、もともとここにバインドされていた ServiceConnection com.android.vending.licensing.LicenseChecker@471cc039 をリークしました
このリークの原因となるコードonCreate()
は次のとおりです。
mLicenseCheckerCallback = new MyLicenseCheckerCallback();
mChecker.checkAccess(mLicenseCheckerCallback);
どうすればこの漏れを取り除くことができますか?
MyLicenseCheckerCallback をメンバーに割り当てないようにしました。おそらく、アクティビティがonPause()
コールバックへの参照になったときに、リークの原因であると考えました。
mChecker.checkAccess(new MyLicenseCheckerCallback());
しかし、それは漏れを取り除きませんでした。
更新:以下の @zapl のコメントのおかげで、Google のLicenseChecker.java
:
/** Unbinds service if necessary and removes reference to it. */
private void cleanupService() {
if (mService != null) {
try {
mContext.unbindService(this);
} catch (IllegalArgumentException e) {
// Somehow we've already been unbound. This is a non-fatal error.
Log.e(TAG, "Unable to unbind from licensing service (already unbound)");
}
mService = null;
}
}
最初は呼び出しを怠っているのではないかと思いましたが、再確認したところmChecker.onDestroy();
、アクティビティのonDestroy()
.
私もチェックインonDestroy()
しましLicenseChecker.java
たが、呼び出していunbindService
ます:
/**
* Inform the library that the context is about to be destroyed, so that
* any open connections can be cleaned up.
* <p>
* Failure to call this method can result in a crash under certain
* circumstances, such as during screen rotation if an Activity requests
* the license check or when the user exits the application.
*/
public synchronized void onDestroy() {
cleanupService();
mHandler.getLooper().quit();
}
それで、実際に何が起こっているのですか?
これは LVL のバグですか?