dispose method

Future<void> dispose()

Disposes the native ad to free native resources (the underlying WebView and, for backfill ads, the AdMob native ad).

Call this once the ad is no longer displayed — for example when the widget hosting AdropNativeAdView is removed from the tree. The instance cannot be reused after dispose; create a new AdropNativeAd to request another ad. Failing to dispose leaks the native WebView (~5–15 MB per instance), which can lead to OOM crashes in feed-style screens.

Implementation

Future<void> dispose() async {
  if (_disposed) return;
  _disposed = true;
  _adropEventObserverChannel?.setMethodCallHandler(null);
  return await _invokeChannel.invokeMethod(AdropMethod.disposeAd, {
    "adType": AdType.native.index,
    "requestId": _requestId,
  });
}