Skip to main content
Samsung Developer Program

Unsubscribe to Plugin Events

To prevent memory leaks or to free memory, unsubscribe to OpenIAB plugin events via the OpenIABEventManager class, which unregisters any listeners that were previously set in Awake().

In City Flyer, unsubscribing is implemented in the onDestroy() class. 

In Unity, onDestroy() is invoked when the class is destroyed.

Shop.cs
// Remove listeners when the application exits

private void onDestroy()
    {
        // Remove listeners from the event manager to avoid nasty leaks
        OpenIABEventManager.billingSupportedEvent -= onBillingSupported;
        OpenIABEventManager.billingNotSupportedEvent -= OnBillingNotSupported;
        OpenIABEventManager.queryInventorySucceededEvent -= OnQueryInventorySucceeded;
        OpenIABEventManager.queryInventoryFailedEvent -= OnQueryInventoryFailed;
        OpenIABEventManager.purchaseSucceededEvent -= OnPurchaseSucceeded;
        OpenIABEventManager.purchaseFailedEvent -= OnPurchaseFailed;
        OpenIABEventManager.consumePurchaseSucceededEvent -= OnConsumePurchaseSucceeded;
        OpenIABEventManager.consumePurchaseFailedEvent -= OnConsumePurchaseFailed;
        OpenIABEventManager.transactionRestoredEvent -= OnTransactionRestored;
        OpenIABEventManager.restoreSucceededEvent -= OnRestoreSucceeded;
        OpenIABEventManager.restoreFailedEvent -= OnRestoreFailed;
    }
  • Was this article helpful?