You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading to 20.0.0 I bumped into a memory leak after loading ads with the templates. Just sharing my findings for anyone else bumping into it.
I'm using #17 since the latest master is not working with 20.0.0.
private var nativeAd: NativeAd? = null
private fun loadAd() {
val adLoader = AdLoader.Builder(context, getAdId())
.forNativeAd { nativeAd: NativeAd ->
this.nativeAd = nativeAd
val styles = NativeTemplateStyle.Builder().build()
adTemplate.setStyles(styles)
adTemplate.setNativeAd(nativeAd)
}
.build()
adLoader.loadAd(AdRequest.Builder().build())
}
Fix for the memory leak:
fun onDestroyView() {
nativeAd?.destroy()
// adTemplate.destroyNativeAd() // I'm not using this because it's not checking for null on the NativeAd
adTemplate.nativeAdView.destroy() // This was the part I didn't expect to be needed
adTemplate.removeAllViews()
}
The text was updated successfully, but these errors were encountered:
After upgrading to 20.0.0 I bumped into a memory leak after loading ads with the templates. Just sharing my findings for anyone else bumping into it.
I'm using #17 since the latest master is not working with 20.0.0.
Fix for the memory leak:
The text was updated successfully, but these errors were encountered: