Skip to content

Commit 6692eb5

Browse files
committed
docs(ads): clarify ad disposal logic in InArticleAdLoaderWidget
Updated the comment in the `dispose` method of `InArticleAdLoaderWidget` to be more explicit about why the ad object is not disposed of there. This reinforces that the ad's lifecycle is managed by the `InlineAdCacheService` and that disposal only happens when the entire article context is cleared.
1 parent 5adc718 commit 6692eb5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/ads/widgets/in_article_ad_loader_widget.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ class _InArticleAdLoaderWidgetState extends State<InArticleAdLoaderWidget> {
118118

119119
@override
120120
void dispose() {
121-
// The ad is intentionally not disposed of here. The InlineAdCacheService
122-
// is responsible for managing the ad's lifecycle. The cache for an
123-
// article context is cleared when the user navigates away from the
124-
// article details page, which is handled by other parts of the app
125-
// (e.g., a higher-level widget's dispose method).
121+
// The ad object (_loadedAd) is intentionally not disposed of here.
122+
// Its lifecycle is managed by the InlineAdCacheService. The cache for this
123+
// article's context is cleared when the user navigates away from the
124+
// article details page, which is the correct and only time these in-article
125+
// ads should be disposed. This prevents ads from being destroyed when they
126+
// are part of a list that scrolls out of view.
126127
if (_loadAdCompleter != null && !_loadAdCompleter!.isCompleted) {
127128
// Complete normally to prevent crashes
128129
_loadAdCompleter!.complete();

0 commit comments

Comments
 (0)